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

最后都变了- 提交于 2019-12-13 12:07:20

问题


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"}]})

回答1:


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',



回答2:


The correct answer is

jsonpCallback: 'callback123'


来源:https://stackoverflow.com/questions/7391707/jquery-ajax-with-jsonp-not-invoking-success-callback-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!