I am attempting to make a jsonp call with jQuery 1.7 but when the call returns I get the following error:
Uncaught TypeError: Object function ( response ) { responseContainer = [ response ]; } has no method 'json'
When inspecting the data being returned I noticed that '.json' is being appended to the callback function name:
jQuery17206211688306648284_1336426518269.json({"..."})
Here is the code that is making the request:
$.ajax({
url: "...",
dataType: 'jsonp',
success: function(data) {
return console.log(data);
}
});
Answer:
As adeneo said the server was trying to specify a callback function of 'json' this is handled by setting the following parameter on the $.ajax call:
jsonpCallback: 'json'
.jsonto the function name provided by jQuery. Therefore, when the script runs, thejQuery17206211688306648284_1336426518269function is found, and it tries to look up a.jsonproperty on the function object, and invoke it as if it was a method of the object.jsonpCallback: 'foo'to your request, and create an object in global scope.window.foo = { json: function(data) { console.log(data);} };I'm betting the server will returnfoo.json({"..."}), invoking the object/method you created.