我目前正在进行跨域数据传输,我遇到了一个非常大的块,我花了几个小时尝试让它工作,这似乎是正确的方式,所以任何指针都会得到很大的接收。
我使用jquery &从json_encodes数据的php页面返回一个id;
我的jquery代码是`
$.getJSON("http://www.icetrack.it/scripts/php/data/ipAddress.php",
{
location: locationVar,
user_key: user_key,
refer: refer,
title: title,
async:false,
dataType: 'json',
success: function(data) {
alert(data);
}
},"json");
它与只输出以下内容的php页面进行对话,
echo json_encode(array("id"=>"$id")); ?>
此页面将输出JSON
{"id":"198"}
然而,我所有的jquery返回的都是一个未定义的变量,我哪里错了这简直是疯了!
谢谢大家!
发布于 2012-01-14 14:06:04
您向$.getJSON()
传递了错误的参数--您提供的许多参数只适用于$.ajax()
。
特别是,$.getJSON()
的data
参数用于发送到服务器的CGI参数,而不是任意的$.ajax()
参数。
试试这个:
$.ajax({
url: "http://www.icetrack.it/scripts/php/data/ipAddress.php",
data: {
location: locationVar,
user_key: user_key,
refer: refer,
title: title
},
async:false,
dataType: 'json',
success: function(data) {
alert(data);
}
});
https://stackoverflow.com/questions/8862656
复制