Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
});
like image 565
Nico van Wijk Avatar asked Sep 09 '15 20:09

Nico van Wijk


2 Answers

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

like image 74
Charlie Avatar answered Oct 06 '22 00:10

Charlie


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;
}
like image 45
Sparkm4n Avatar answered Oct 06 '22 01:10

Sparkm4n