Updates from September, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • Kevin Chiu 3:14 am on September 22, 2010 Permalink | Reply  

    JSONP in Rails 3 

    Your URL:
    http://localhost:3000/api/get_items?callback=awesome

    In your api controller:
    render :json => @items.to_json, :callback => params[:callback]

    Result:
    awesome(["item1", item2"]);

    This gives you cross-domain JSONP. The callback variable in the URL is optional.

    There’s no need to roll your own render_json.

     
    • Ramana 1:36 am on November 22, 2010 Permalink

      Hi,

      I am using Rails 2.3.5

      For this is it possible to have the cross domain json call.

      I am using the same code which you have but i am getting the exact out put in my application but in cross domain i can’t get any results i mean i am not getting any response from the server. But server is getting the request .

      Can you please help me out.

      Thanks in Advance,

      Ramanavel Selvaraju

    • Kevin Chiu 9:08 am on December 4, 2010 Permalink

      Can you paste the request and response into gist.github.com and give me the link?

    • jävi 9:28 am on May 5, 2011 Permalink

      I had problems because Rails 3 ajax request (with Jquery) were expecting a JSONP response, making the browser to throw an error if normal JSON was received. This solved my problem.

      Thanks for sharing the line.

  • Kevin Chiu 11:39 am on September 3, 2010 Permalink | Reply
    Tags: ,   

    China July 4 – Sep 3 

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel