AJAX responseXML errors

前端 未结 7 2258
傲寒
傲寒 2020-12-21 02:41

I\'ve been having some weird issues when it comes to make an AJAX request and handling the response.

I am making an ajax call for an xml file. however when i get the

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 02:59

    This problem occurs mostly when content type is mis-detected by the browser or it's not sent correctly.

    Its easier to just override it:

    var request = new XMLHttpRequest(); 
    request.open("GET", url, false); 
    request.overrideMimeType("text/xml");
    request.send(null); 
    return request.responseXML; 
    

    Not sure why... This problem occurs only with Safari and Chrome (WebKit browsers, the server sends the headers correctly).

提交回复
热议问题