开发者

IE6 and 7 issue with innerHTML

开发者 https://www.devze.com 2023-04-08 07:38 出处:网络
IE6 and 7 issue with innerHTML I have used ajax in the application i have develop, but there are issues with IE6 and IE7, they doesn\'t support innerHTML. What must be used to fixed this issue and to

IE6 and 7 issue with innerHTML

I have used ajax in the application i have develop, but there are issues with IE6 and IE7, they doesn't support innerHTML. What must be used to fixed this issue and to be a cross browser compatible?

the sample code looks like this.

function showFAQ(src, target){
     xhr.onreadystatechange=function(){
       if(xhr.readyState == 4 && xhr.status == 200){
         document.getElementById('resultDiv').innerHTML=xhr.responseText;
       }
    }

    str = "?action=get&request="+src;
    xhr.open("GET", "./requests/data.php"+encodeURI(str), true);
    xhr.send();
}

In FireFox, IE8 and other major browsers works fine. Just the problem is with IE6 and 7.

Any help/advice will be开发者_Python百科 appreciated.

Thanks


IE cannot update readonly elements using innerHTML... consider this too.. :)


Try

var xmlHttp;

function getXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer 6+
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

var xhr = getXmlHttpObject();


Update

Try adding

xhr.send(null);

after

str = "?action=get&request="+src;
xhr.open("GET", "./requests/data.php"+encodeURI(str), true);


innerHTML is supported as of IE5. I think you problem is the use of the xmlhttprequest object. That one is only supported as of IE7. You can however ActiveXObject as stealthyninja's code uses.

0

精彩评论

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

关注公众号