IE6 and 7 issue with innerHTML

烈酒焚心 提交于 2019-12-10 11:58:19

问题


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 appreciated.

Thanks


回答1:


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);



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/7571831/ie6-and-7-issue-with-innerhtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!