开发者

Why AJAX does not work in Netscape Navigator?

I am using the following code in which the function is called onclick:

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// co开发者_如何学Gode for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","ajax_info.txt",true);
    xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

It works in all the browser except netscape navigator


It doesn't work in Netscape Navigator because this (ancient) browser doesn't support either the XMLHttpRequest object, nor the ActiveX alternative that works in older versions of IE.

The XMLHttpRequest object wasn't even invented when the last version of Navigator was released, and the ActiveX alternative only ever worked with IE.

If you're really desperate to make a modern Ajax site work on an ancient browser like this, you might be able to do something using the old 'hidden iframe' technique hack, but it'd be lot of work for virtually zero gain, and you'll still have loads of other issues to solve in order to support the browser.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜