jsonpCallback函数不起作用 [英] jsonpCallback function not working
问题描述
更新1:
我刚刚从jquery 1.4.4升级到1.6.1.这对原始问题中的脚本有何影响?
I've just upgraded from jquery 1.4.4 to 1.6.1. How does that effect the script in the original question?
原始问题:
就像我测试的那样,我做到了:
Just as I test, I did:
$(document).ready(function() {
get_jsonp_feed();
function get_jsonp_feed() {
$.ajax({
url: 'http://www.remote_host.co.uk/feed.php',
type: 'GET',
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'jsonpCallback',
error: function(xhr, status, error) {
alert("error");
},
success: function(jsonp) {
alert("success");
}
});
}
function jsonpCallback(data){
alert("jsonpCallback");
}
});
我希望收到2条警报,第一个显示success
,第二个显示jsonpCallback
.但是我只得到第一个警报success
.为什么第二个警报没有显示?
I was expecting to get 2 alerts, the first showing success
and the second showing jsonpCallback
. But I am only getting the first alert success
. Why is the second alert not showing up?
推荐答案
George是正确的,将jsonp参数设置为false-从jQuery 1.5开始(因此,设置方式取决于jQuery版本).我不相信您提供的回调名称是作为一个函数调用的(而是在提供给服务器的URL中提供的名称).如果您获得成功,那么您已经收到了数据.好奇:您是否为开发人员设置了主机条目,因为我尝试进行一些测试,并且 http ://www.remote_host.co.uk/feed.php 不能为我解决.
George is correct, set the jsonp param to false -- as of jQuery 1.5 (so, how you set this up is jQuery version dependent). I don't believe that your supplied callback name is invoked as a function (rather, it is the name provided in the URL presented to the server). If you are getting success, then you have received the data. Curious: do you have a hosts entry set up for dev, because I tried to do some testing, and http://www.remote_host.co.uk/feed.php does not resolve for me.
这篇关于jsonpCallback函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!