在Safari中,XML响应不起作用

In Safari, XML response is not working

本文关键字:响应 不起作用 XML Safari      更新时间:2023-09-26

我们已经试过了,请检查并给出建议。

function GetXmlHttpObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
} 

function show(url,did)
{
    divId=did;
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    if(url.indexOf("?")!=-1)
    url=url+"&sid="+Math.random();
    else
    url=url+"?sid="+Math.random();
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);
} 
function stateChanged()
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        document.getElementById(divId).style.display='block';
        document.getElementById(divId).innerHTML=xmlHttp.responseText;
    }
}

这里看起来根本没有使用jQuery。Ajax在不同浏览器之间的处理方式非常不同,但jQuery提供了抽象,所以您不必担心它。查看API文档,可以是较低级别的.ajax()方法,也可以是一些更简单的简写方法,如.get().post()

http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.post/

尝试用&&:替换逻辑||运算符

function stateChanged()
{ 
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
    { 
        document.getElementById(divId).style.display='block';
        document.getElementById(divId).innerHTML=xmlHttp.responseText;
    }
}