Thomas Thomas - 1 year ago 238
jQuery Question

parsererror after jQuery.ajax request with jsonp content type

I am using jQuery Version 1.5.1 to do the following ajax call:

dataType: 'jsonp',
data: { api_key : apiKey },
url: "" + resource + ".json",
success: function(data) { console.log(data); },
error: function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); console.log(textStatus); }

The server responds with a valid json object:

"response": {

But the success callback is never called, instead the error callback produces this output:

jQuery15109935275333671539_1300495251986 was not called

Why does this happen?

I am using no additional libraries to jQuery.


If I try to make the ajax call with "json" as dataType instead of "jsonp", the server responds with an empty string.

Answer Source

JSONP requires that the response be wrapped in some kind of callback function.

So the server should respond with:


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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download