parsererror after jQuery.ajax request with jsonp content type

JSONP requires that the response be wrapped in some kind of callback function, because it works by injecting a script tag into the document as a mechanism to load data from another domain.

Essentially, what happens is a script tag gets dynamically inserted into the document like so:

<script src="http://the.other.server.com/foo?callback=someFn"></script>

callback is dependent on the resource you’re calling, it’s common for the parameter to be callback though.

someFn is then used to process the returned data from the server, so the server should respond with:

someFn({theData: 'here'});

The someFn is passed as part of the request, so the server needs to read it and wrap the data appropriately.

This is all assuming you’re grabbing the content from another domain. If so, you’re limited by the same origin policy: http://en.wikipedia.org/wiki/Same_origin_policy

Leave a Comment