开发者

ajax issue on IE8

开发者 https://www.devze.com 2022-12-19 08:25 出处:网络
I have an old site that uses xml documents, and when I created it i had firefox and IE7 to test on, and it worked just great. Since then, IE8 appeared, and it seams that the site does no longer work p

I have an old site that uses xml documents, and when I created it i had firefox and IE7 to test on, and it worked just great. Since then, IE8 appeared, and it seams that the site does no longer work properly. This is the current code:

if (window.XMLHttpRequest) 
    {
        XMLHttpRequestObject  = new XMLHttpRequest();
        XMLHttpRequestObject.overrideMimeType("text/xml");
        XMLHttpRequestObject.open("GET", "produse.xml", true);
  开发者_运维知识库      XMLHttpRequestObject.onreadystatechange = function()
        {   
            if (XMLHttpRequestObject.readyState == 4) 
            {
                xmlDocument = XMLHttpRequestObject.responseXML;
                removeWhitespace(xmlDocument);                                          
            }
        }
    XMLHttpRequestObject.send(null);
    } 
    else if (window.ActiveXObject) 
        {
            xmlDocument= new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDocument.async=false; 
            if (xmlDocument .readyState == 4)
            {
                xmlDocument.load("produse.xml");    
            }
        }

But I get this error:

Message: Object doesn't support this property or method
Line: 19
Char: 3
Code: 0

which relates to:

XMLHttpRequestObject.overrideMimeType("text/xml");

What should I use instead?


This page shows what the differences are between firefox/ie/ie8 are and has some examples of how to do it:

http://www.javascriptkit.com/jsref/ajax.shtml

Mostly it says that IE8 does not support this method and you have to make sure your server is adding the proper header (text/xml) to the outgoing response.

It also has a link to http://www.javascriptkit.com/dhtmltutors/ajaxgetpost3.shtml that explains the common pitfalls and IE problems.

It says do:

if (mygetrequest.overrideMimeType)
 mygetrequest.overrideMimeType('text/xml')


jQuery would be my choice. It is a lot faster and is cross browser supported and on a CDN.

You could strip that code down to just a few lines.

$.get('ajax/test.html', function(data) {
  $('.result').html(data);
  alert('Load was performed.');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消