【发布时间】:2012-01-18 10:29:14
【问题描述】:
以下是我拥有的 Java Script 代码。
//URL = http://dev.stage.com/restapi/vc/auth/sessions/login/
//parametersURL = user.login=******&user.password=******
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlHttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open( "POST", URL, true );
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", parametersURL.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(parametersURL);
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert(xmlHttp.responseText);
return xmlHttp.responseXML;
}
}
在 IE8 中测试时,我在警告框中得到了正确的响应。
<response status="success"><value type="string">
uX-DjjZ2XrSB_GAfjSLTapOJvyvd2U9Y8MHsQzrvFeo.</value></response>
但是在 Chrome 和 Firefox 中测试时。响应为空。使用 FireBug 检查时,响应为空,并且在 XML 中出现以下错误
XML Parsing Error: no element found Location: moz-nullprincipal:{9fc08684-36c5-42b2-
b641-e9400c6e627f} Line Number 1, Column 1:
在 Firefox 中使用海报插件我可以得到正确的响应。
请告诉我是什么问题
【问题讨论】:
-
更改了标题,以便未来的用户很容易得到这样的问题。如果您不喜欢它,请还原它
标签: javascript xml xmlhttprequest http-post httpresponse