I have a jQuery each loop that runs through a list of three JSONP urls, but, a random number of them just fail with the error: Uncaught TypeError: Property 'callback' of object [object Window] is not a function.
It is usually one or two and sometimes none but it is never all of them, I think that it has to do with the asynchronous part but I don’t know how to fix it.
Here is my code:
var feeds = ["JSONPUrl", "JSONPUrl", "JSONPUrl"];
$.each(feeds, function(index, feedUrl) {
$.ajax({
type: "GET",
url: feedUrl,
processData : true,
data: {
tagmode: "any",
jsonp: "callback",
callback: "callback"
},
jsonpCallback: "callback",
dataType: "jsonp",
success: function(data) {
// Do some DOM manipulations with the data
},
error: function(x,y,z) {
}
});
});
Any ideas?
Your URL looks like
?callback=callback, because of the hard-codedcallbackproperty. Remove this, jQuery will automatically define temporary functions with random names for the JSONP callback.If you really want to execute a function called
callbackon success, include this in thesuccesshandler.Regarding the comments: If your server expects the JSONP callback parameter to be called “jsonp” instead of “callback”, use: