javascript $.getJSON 在 Internet Explorer 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10315211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
$.getJSON not working in Internet Explorer
提问by Spoike
I am using following code to grab data from JSON.
我正在使用以下代码从 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);
});
});
It works in Mozilla, Chrome and other browser but not in IE. (Not in any Version).
它适用于 Mozilla、Chrome 和其他浏览器,但不适用于 IE。(不在任何版本中)。
回答by Spoike
$.getJSON
has a tendency to cache results in IE. Use $.ajax
instead.
$.getJSON
倾向于在 IE 中缓存结果。使用$.ajax
来代替。
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); }
});
Make sure you have cache: false
.
确保你有cache: false
.
UPDATE:
更新:
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.
OP 实际使用的请求 url 似乎是主机的配置问题。使用 IE Web 浏览器直接访问 url 会导致主机中止。除了向主机报告问题之外,您无能为力,例如向主机的网站管理员发送电子邮件。
回答by bsuttor
I had the same error on a page, and I added these lines :
我在页面上遇到了同样的错误,我添加了以下几行:
<!--[if lte IE 9]>
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.0/jquery.xdomainrequest.min.js'></script>
<![endif]-->
and it finaly works for me ;) no more error for IE9
它最终对我有用;) IE9 不再有错误
This post helps me jQuery Call to WebService returns "No Transport" error