Casey Flynn Casey Flynn - 1 month ago 11
Ajax Question

jQuery .ajax() with jsonp not invoking success callback function

I have a facebook iframe application that makes a cross domain request to my server and requests data in JSONP format. This is my client side code:

jQuery.ajax({
url: '***',
type: 'post',
data: {
method: 'set_user_prizes'
},
dataType: 'jsonp',
jsonp: false,
jsonpCallbackString: 'callback123',
success: function(data, textStatus, jqXHR){
console.log('success_function');
console.log(data);
}
});


The problem is my success callback method isn't being invoked and I'm not sure why. Using Firebug I can see my server's response:

callback123({"success":true,"associated_prizes":[{"prizes_id":"6"},{"prizes_id":"1"}]})

Answer

Remove the word String from the callback key as is illustrated in the following transformation. The value needs to remain a string.

Change:

jsonpCallbackString: 'callback123',

to

jsonpCallback: 'callback123',