0

This jQuery.getJSON works for me in Safari, but not FF or Chrome. In Safari, I get alerts with json name/value pairs. In FF/Chrome. I get the 3 error alerts (all returning empty strings). Any ideas what I'm doing wrong here?

<!-- language: javascript -->

$.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {   
    alert("text Status: " + textStatus);
    alert("error thrown: " + errorThrown);
    alert("response:" + XMLHttpRequest.responseText);
}});

$.getJSON("http://example.com/webservice",
  {
  },
  function(data) {
    for(var key in data){
             var attrName = key;
             var attrValue = data[key];
        alert('name='+ attrName + ' value=' +attrValue);
      }
  });
Sumurai8
  • 20,333
  • 11
  • 66
  • 100
user738497
  • 31
  • 1
  • 4

1 Answers1

0

What MIME type is being returned? A similar looking problem was described here, with a workaround: jQuery .getJSON Firefox 3 Syntax Error Undefined

Community
  • 1
  • 1
lod3n
  • 2,893
  • 15
  • 16
  • the service is returning content-type of text/html – user738497 May 04 '11 at 18:27
  • @user738497: It should return a content-type of `application/json` – gen_Eric May 04 '11 at 18:31
  • Content type is now set to application/json. No change in behavior – user738497 May 04 '11 at 23:45
  • Try using FireBug in Firefox, and examine the actual response. Is it well formed JSON? – lod3n May 05 '11 at 17:20
  • Yes, I've tested it with JsonLint repeatedly . It is valid JSON. Damned mysterious. – user738497 May 05 '11 at 17:55
  • The problem seems to be that when I make the getJSON request, I'm getting back a status 0 error. The error handling above does not print out the error. However this does: `$.ajaxSetup({ error:function(x,e){ if(x.status==0){ alert('You are offline!!\n Please Check Your Network.'); }` – user738497 May 06 '11 at 17:02
  • Add this to your ajaxSetup: beforeSend: function(xhr){jQuery(window).bind('beforeunload',function(){xhr.abort();});} Found here: http://steveweintraut.blogspot.com/2009/12/firefoxsafari-ajax-status-code-0-bug.html – lod3n May 06 '11 at 19:55