Nico van Wijk
Nico van Wijk

Reputation: 269

Different behavior for empty XML response between IE and Firefox

I'm using jQuery to read an XML file. Sometimes the XML is empty, and I expect the error function (no_info) is executed because the file is not formatted according to the dataType.

In IE 10 the Error function is executed. But in Firefox (40.0.2) the success function (parse) is executed. Why both browsers behave differently and which one is correct?

$.ajax({
  url: '/~play/shout.xml',
  dataType: "xml",
  success: parse,
  error: no_info
});

Upvotes: 16

Views: 755

Answers (4)

Sparkm4n
Sparkm4n

Reputation: 644

which JQuery version do you use? I use the most actual and with my ajax function I couldn't encounter any issues. That's my code

function sync(arg, callback){   //ajax result 
    $('.loader').show();
    $.ajax({ 
        method: 'GET',
        url: 'liveSearch.php',
        data: arg, // send argument and update
        success: function(data, status, xhr){
         $('.loader').hide();
         callback(data);
        },
        error: function(xhr, ajaxOptions, thrownError){
            console.log(thrownError);
        }
   });  
}

function onCallback(data) {
        result = data;
}

Upvotes: 1

Charlie
Charlie

Reputation: 183

Looks like there's a bug in IE

how about you handle it yourself?

 function parseXml(xml) {

   if ($.browser.msie)  {

   if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp = new XMLHttpRequest();
   }else {// code for IE6, IE5
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   xmlhttp.open("GET", "XML_file.xml", false);
   xmlhttp.send();
xmlDoc = xmlhttp.responseXML;

xml = xmlDoc;
} 
return xml;

}

previous answer

Upvotes: 2

Narendra Selot
Narendra Selot

Reputation: 24

instead of just /~ try passing the whole URL from which you want to retrieve the XML file.

Upvotes: 0

Sush
Sush

Reputation: 133

dataType parameter merely indicates what "Content-Type" header you are expecting. As long as the file exists and served with a valid Content-Type Success function should be triggered.

Upvotes: 0

Related Questions