【问题标题】:XML HTTP RESPONSE ISSUE : XML Parsing Error: no element found Location: moz-nullprincipalXML HTTP 响应问题:XML 解析错误:找不到元素位置:moz-nullprincipal
【发布时间】: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


【解决方案1】:

这是跨域问题。在 IE 中没有正确处理,因此它起作用了。使用 jsonp 进行跨域请求,效果非常棒。

【讨论】:

    猜你喜欢
    • 2013-05-31
    • 2017-02-01
    • 2012-08-22
    • 2017-08-03
    • 2021-01-17
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    相关资源
    最近更新 更多