Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

javascript - $.getJSON not working in Internet Explorer

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);
    });
 });

It works in Mozilla, Chrome and other browser but not in IE. (Not in any Version).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

$.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); }
});

Make sure you have 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...