$ .getJSON在Internet Explorer中不起作用 [英] $.getJSON not working in Internet Explorer
问题描述
我正在使用以下代码从JSON获取数据.
I am using following code to grab data from JSON.
$(document).ready(function()
{
$.getJSON("http://www.example.com/data.php?id=113&out=json", function(data) {
$.each(data.issue.page, function(i,item) {
imagesJSON[i] = item["@attributes"];
});
alert(imagesJSON.length);
});
});
它可以在Mozilla,Chrome和其他浏览器中使用,但不能在IE中使用. (没有任何版本).
It works in Mozilla, Chrome and other browser but not in IE. (Not in any Version).
推荐答案
$.getJSON
倾向于在IE中缓存结果.代替使用 $.ajax
.
$.getJSON
has a tendency to cache results in IE. Use $.ajax
instead.
在您的情况下,相关的呼叫应如下所示:
The related call should be something like this in your case:
// Not really sure if you've forgot to var
var imagesJSON = [];
$.ajax({
url: "www.example.com/data.php?id=113&out=json",
cache: false,
dataType: "json",
success: function(data) {
$.each(data.issue.page, function(i,item) {
imagesJSON[i] = item["@attributes"];
});
alert(imagesJSON.length);
},
error: function (request, status, error) { alert(status + ", " + error); }
});
确保您拥有cache: false
.
更新:
在主机上,OP实际使用的请求URL似乎是一个配置问题.直接使用IE Web浏览器访问url会导致主机中止.除了向主机报告问题,就像向主机的网站管理员发送电子邮件一样,您无能为力.
It appears to be a configuration issue at the host with the request url that the OP actually uses. Going to the url directly with IE web browser results in an abort from the host. You can't do much than to report the issue to the host, like an email to the webmaster of the host.
这篇关于$ .getJSON在Internet Explorer中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!