views:

75

answers:

1

From googling/forums I think there could be two issues, neither of which I know how to fix:

1) I need to do something with the jsonp callback in the node.js request (which was generated automatically by jquery b/c of the callback=? param) - either add it to the header (where? and how?) or add it to the json response (again, where? and how?)

2) There could be some issue with the node.js request connection staying open, and therefore never signaling the callback?

jquery code:

url = http://nodeapp.com/users?screen_name=s&callback=?
$.getJSON(this_url, function(data){
     var users = data
     $.each(users, function(i, item){
     $("#users").append(item...);
})

node.js/express.js (coffee script) code:

get '/user', ->
   users.all... =>
      @header("Content-Type", 'application/javascript')
      @respond 200, JSON.stringify(users)
+1  A: 

I am not familiar with RoR but when you request http://nodeapp.com/users?screen_name=s&callback=foo, the response should look like this:

foo({ first_name: 'John', last_name: 'Smith' });

and not:

{ first_name: 'John', last_name: 'Smith' }

As far as the callback=? parameter is concerned you don't need to modify it, jQuery will pass a random value so that the anonymous callback could be invoked.

Darin Dimitrov