10

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).

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 4
    if we could see the JSON result... – gdoron Apr 25 '12 at 12:05
  • 2
    what jquery version and is this link on the domain your script is on? – Dominic Apr 25 '12 at 12:06
  • 2
    Results of adding debug code inside the callback? – Quentin Apr 25 '12 at 12:07
  • it will display nothing. not even any error. –  Apr 25 '12 at 12:07
  • Try it with `$.ajax` and `cache: false` – binarious Apr 25 '12 at 12:09
  • 3
    Could be a same origin policy issue, but then it ought to not work in the other browsers if that was the case. Using $.ajax will allow you to set an `error: function(x) { }` block and then catch the error and look at `x.responseText` to see if an error is returned. – SpaceBison Apr 25 '12 at 12:10
  • IE gives me error like **Error, No transport** –  Apr 26 '12 at 05:34
  • @ketan: what is the actual url and could you provide us the json data? – Spoike Apr 26 '12 at 06:56
  • @ketan: It appears that bluetoad doesn't allow IE to access their data.php url (you get the same problem when you go to that link directly in IE). So it seems like they have a configuration issue, Nothing to do here other than to contact them about the issue. – Spoike Apr 26 '12 at 07:48
  • ok thanks for reply and help me a lot. u have good knowledge. –  Apr 26 '12 at 07:54

2 Answers2

18

$.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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Spoike
  • 119,724
  • 44
  • 140
  • 158
  • I use this. Is there any problem `$.ajax({ url: "http://www.xyz.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); }` –  Apr 25 '12 at 12:24
  • @ketan: are you sure you're typing it in right? the value for the key error (which is that function you have there) should be inside the parameter array for the `$.ajax` function. – Spoike Apr 25 '12 at 14:28
  • 4
    The above things give me error in IE like **Error, No transport** –  Apr 26 '12 at 05:21
2

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

This post helps me jQuery Call to WebService returns "No Transport" error

Community
  • 1
  • 1
bsuttor
  • 2,716
  • 2
  • 17
  • 10