2010-11-22 6 views
0

I 내가 제어기문제점 2.3.5

def unique_email 
count = User.count(:all, :conditions => ['email = ?',params[:email]]) 
result = Hash.new() 

if count > 0 
    result[:text] = "false" 
else 
result[:text] = "true" 
end 
respond_to do |format| 
    format.json { 
    render :json => result 
    } 
end 

에서 다음

<script> jQuery.getJSON("http://localhost:3003/home/unique_email/[email protected]&callback=result", { format: "jsonp" }, function(result) { alert(result.text) }); </script>

사용하고 크로스 도메인 검사 용해서 getJSON() 메소드를 사용할 end

동일한 도메인에서 경고가 표시됩니다. 즉, 응용 프로그램에 경고가 표시되지만 코드를 옆으로두면 응용 프로그램이 아니라는 의미입니다. 어떤 오류가 발생하지만 응용 프로그램 작업이 호출됩니다 ..하지만 응용 프로그램에서 어떤 응답도 얻지 못하고 있습니다.

도움이 될 것입니다.

감사 & 관련,

Ramanavel Selvaraju.

답변

0

나는 이것에 대한 대답을 발견,

총리는 응용 프로그램 컨트롤러에 render_json 방법을 추가해야합니다.

private 

    # render json, but also allow JSONP and handle that correctly 
    def render_json(json, options={}) 
     callback, variable = params[:callback], params[:variable] 
     logger.debug("render json or jsonp? Callback = #{callback}, Variable=#{variable}") 
     response = begin 
     if callback && variable 
      "var #{variable} = #{json};\n#{callback}(#{variable});" 
     elsif variable 
      "var #{variable} = #{json}" 
     elsif callback 
      "#{callback}(#{json});" 
     else 
      json 
     end 
     end 
     render({:content_type => :js, :text => response}.merge(options)) 
    end 

그래서 우리는 jQuery 아약스에서 jsonp로 데이터 유형을 얻을 수 있습니다.