我正在尝试从服务器端(java)获取 xml 响应。我在Fiddler中进行了检查,它按预期返回响应,状态码为 200,但是我的 Jquery 发布函数正在发送对错误的响应,给我一个警报“从服务器获取 xml 时出错”。是 i18n 的问题吗?我能够读取和解析其他 xml 响应,我怎样才能对这种响应做同样的事情
我的代码:
var jqxhr =$.post(redirectMainUrl+"globalaction.action", {
sessiontoken: sessiontoken,
action: "getFile",
absFileName: file_path
},
function(xml1) {
alert($(xml1).find("lastDayErrorLogs")
.children("log")
.children("logEvent")
.attr("message"));
})
.error(function() {
if(jqxhr.responseText == 'INVALID_SESSION') {
alert("Your Session has been timed out");
window.location.replace(communities);
} else {
alert("Error while getting xml from server");
goToHomePage();
}
});
来自服务器的响应 (xml)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="client.xsl"?>
<client version="1.0" >
<product>
<lastDayErrorLogs><log>
<logEvent timestamp="2013-1-15_10:56:6" severity="1" messageCode="CNX_53021" message="Solicitação inválida recebida." user="" stacktrace="" service="Rep_Service_Prd" serviceType="RS" clientNode="node01_jbpaetlsr2" pid="11900" threadName="11772" context="">
</logEvent>
</log></lastDayErrorLogs></product>
</client>
由于以下属性的内容导致的问题
message="Solicitação inválida recebida."
更新:
在@Unsung 的评论之后,我检查jqxhr.responseText
了它是否包含响应 xml,所以我想在错误函数中解析 xml。
但即使在对我的error
功能进行更改后,我在 Internet Explorer 8 中也会出现以下错误
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
Timestamp: Tue, 22 Jan 2013 06:57:44 UTC
Message: Invalid XML: <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="client.xsl"?>
<client version="1.0">
<product>
<lastDayErrorLogs><log>
<logEvent timestamp="2013-1-15_10:56:6" severity="1" messageCode="CNX_53021" message="Solicita invda recebida." user="" stacktrace="" service="Rep_Service_Prd" serviceType="RS" clientNode="node01_jbpaetlsr002" pid="11900" threadName="11772" context="">
</logEvent>
</log></lastDayErrorLogs></product>
</client>
Line: 2
Char: 10691
Code: 0
URI: http://xxxx:10270/...include/js/jquery.js
误差函数:
.error(function() {
if (jqxhr.responseText == 'INVALID_SESSION') {
alert("Your Session has been timed out");
window.location.replace(communities);
} else {
alert("Error while getting xml from server");
var xml=StringtoXML(jqxhr.responseText);
var csmXmlDoc = $.parseXML( jqxhr.responseText ),
$csmxml = $( csmXmlDoc ),
$csmTitle = $csmxml.find("product").children("version");
alert($csmTitle.text()+", "+$(xml).find("product").children("version").text());
//goToHomePage();
}
})