A有以下问题。我的代码将HTTP请求发送到ASP处理程序:
var xmlRequest = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
xmlRequest.open("GET", "Handler.ashx?value25="+$('#joKod').val()+"&operType=3");
xmlRequest.setRequestHeader('Content-Type', 'text/xml');
xmlRequest.onreadystatechange = function()
{
if (xmlRequest.readyState == 4)
{
if (xmlRequest.status == 200)
{
alert(xmlRequest.responseXML.xml);
}
}
}
xmlRequest.setRequestHeader("Content-Type", "text/xml");
xmlRequest.send('xml');
我的处理程序创建XML答案
XmlDocument xd=Scoring.CheckLinkFirma(okpo);
resp.Clear();
resp.ContentType = "text/xml";
xd.Save(resp.Output);
然后发回来:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<jo status="client">abc</jo>
<jo status="client">dfh</jo>
</Root>
在Exlorer中,responseXML.xml有值,但Chrome和FF未定义???
答案 0 :(得分:1)
因为那是IE唯一的属性。如果你想获得一个XML,你可以这样做:
function XMLToString(oXML)
{
if (window.XMLHttpRequest) {}//Standards First
else if (window.ActiveXObject) {return oXML.xml;}//Proprietary Second
else {return (new XMLSerializer()).serializeToString(oXML);}//other browsers
}
alert(XMLToString(xmlRequest.responseXML))
或者您可以尝试从xmlRequest.responseText
答案 1 :(得分:0)
我在jQuery中找到了答案。希望它会帮助某人
$.ajax
({
type: "GET",
url: "Handler.ashx?value25="+$('#joKod').val()+"&operType=3",
dataType: "text",
cache: true,
success: function(xml)
{
if (xml)
{
var myXml = $($.parseXML(xml)).find('Root');
}
}
});