jQuery的阿贾克斯()与JSONP没有调用成功的回调函数 [英] jQuery .ajax() with jsonp not invoking success callback function

查看:417
本文介绍了jQuery的阿贾克斯()与JSONP没有调用成功的回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Facebook iframe的应用程序,使一个跨域请求到我的服务器并请求数据JSONP格式。这是我的客户端code:

  jQuery.ajax({
                网址:'***',
                类型:'后',
                数据: {
                    方法:set_user_prizes
                },
                数据类型:JSONP,
                JSONP:假的,
                jsonpCallbackString:callback123,
                成功:功能(数据,textStatus,jqXHR){
                    的console.log('success_function');
                    的console.log(数据);
                }
});
 

现在的问题是我成功的回调方法没有被调用,我不知道为什么。用Firebug我可以看到我的服务器的响应:

  callback123({成功:真正的associated_prizes:[{prizes_id:6},{prizes_id:1}]})
 

解决方案

从所示的那样以下改造回调键删除单词字符串。该值应保留为一个字符串。

修改

  jsonpCallbackString:callback123,
 

  jsonpCallback:callback123,
 

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

解决方案

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

这篇关于jQuery的阿贾克斯()与JSONP没有调用成功的回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆