php - IE 6 不支持我的代码的哪一部分

标签 php javascript ajax function internet-explorer-6

我正在尝试通过ajax将php文件加载到div中。它在除 IE6 之外的所有浏览器中都能正常工作(它不加载 php 文件)。我有一个任务,它也需要在 IE6 中工作。请提出更正建议。

我的index.php文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript">
window.onload = function(){
document.getElementById("aside").innerHTML="<img src='loadingImage.gif'>";
if(XMLHttpRequest) var x = new XMLHttpRequest();
else var x = new ActiveXObject("Microsoft.XMLHTTP");
x.open("GET", "other_content_1.php", true);
x.send("");
x.onreadystatechange = function(){
    if(x.readyState == 4){
        if(x.status==200) document.getElementById("aside").innerHTML = x.responseText;
        else document.getElementById("aside").innerHTML = "Error loading document";
        }
    }
} 
</script>
</head>

<body>
<div id="aside">This is other content</div>
</body>
</html>

我的other_content_1.php文件:

<div id='other-content-1'>
<?php echo 'This text is loading via php command'; ?>
</div>

最佳答案

IE6 在这一行抛出 JavaScript 错误:

if(XMLHttpRequest)

下面是适用于 IE6 的代码(也可能适用于 IE5.5):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript">
window.onload = function(){

    document.getElementById("aside").innerHTML="<img src='loadingImage.gif'>";

    var x = null;

    if (window.XMLHttpRequest) {
        var x = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        var x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
    } else {
        // fallback
    }

    x.open("GET", "other_content_1.php", true);
    x.send("");
    x.onreadystatechange = function() {

        if(x.readyState == 4) {
            if(x.status==200) 
                document.getElementById("aside").innerHTML = x.responseText;
            else 
                document.getElementById("aside").innerHTML = "Error loading document";
        }
    }
} 
</script>
</head>

<body>
<div id="aside">This is other content</div>
</body>
</html>

关于php - IE 6 不支持我的代码的哪一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17392615/

相关文章:

php - 从存储到变量的查询中获取日期的问题

PHP 的 Java ArrayList 等效项

javascript - D3.js 强制有向图,通过使边相互排斥来减少边交叉

javascript - XMLHttpRequest异步读取,如何不使用匿名函数?

javascript - 将 json 数据 POST 到 Bottle

php - 按具有自定义排序优先级的列对数组数组进行排序(不是按字母顺序排列)

php - 组合算法中的循环

php - 在哪里可以找到 Facebook cookie?

javascript - 谷歌地图从具有半径的点获取可能的经纬度范围

PHP/Javascript - 通过 POST 将日期字符串传递给 AJAX 不起作用