IE6和7与innerHTML有关 [英] IE6 and 7 issue with innerHTML

查看:124
本文介绍了IE6和7与innerHTML有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用innerHTML的IE6和7问题

IE6 and 7 issue with innerHTML

我在我开发的应用程序中使用了ajax,但IE6和IE7存在问题,它们不支持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?

示例代码如下所示。

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

在FireFox,IE8和其他主流浏览器中运行正常。问题在于IE6和7。

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

任何帮助/建议都将受到赞赏。

Any help/advice will be appreciated.

谢谢

推荐答案

尝试

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



更新

尝试添加

xhr.send(null);

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

这篇关于IE6和7与innerHTML有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆