2012-01-18 69 views
0

以下是我擁有的Java腳本代碼。XML HTTP響應問題:XML解析錯誤:未找到元素位置:moz-nullprincipal

//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中我能得到正確的反應。

請讓我知道是什麼問題

+1

更改了標題,以便將來的用戶很容易得到問題。如果你不喜歡,請將它還原 – 2012-01-18 10:34:52

回答

1

這是跨域問題。在IE中沒有正確處理,因此它工作。使用jsonp進行跨域請求,它的工作就像一個魅力。