Basic how-to for cross domain jsonp

JSONP requires the cooperation of the server to succeed. You cannot pull random pages using JSONP and expect them to succeed; the server needs to know:

  1. It needs to formulate a JSONP response, rather than a JSON response.
  2. It needs to know the name of the function to wrap the response around.

If you’re unsure on why the server needs to know these, or what the differences are between JSON and JSONP, you should read up on them; or the whole thing will make no sense. For starters, check out Can anyone explain what JSONP is, in layman terms? and http://en.wikipedia.org/wiki/JSONP.

After understanding this a little more, you’ll probably find the server is returning

{ "key": 1, "bar": "foo" }

(which is valid JSON), rather than:

someCallback({ "key": 1, "bar": "foo" })

which is a JSONP response.

Leave a Comment