我正在尝试使用jquery ajax从服务器获取xml。如果我自己在某个地方托管一个xml文件(包含相同的xml数据),我可以使它工作,但是当我尝试从(目标)服务器获取它时,我没有收到任何数据。但是,如果我将服务器URL放在我的浏览器中,我会得到xml,所以网址很好。
我的代码:
$.ajax({
async: false,
type:"GET",
url: url,
crossDomain: true,
data: "user=user1&password=password1&id=2",
dataType:"xml",
success: function(data) { alert(data);},
error: function(event, jqXHR, ajaxSettings, thrownError) {
console.log(JSON.stringify(event, null, 4));
console.log(JSON.stringify(jqXHR, null, 4));
console.log(JSON.stringify(ajaxSettings, null, 4));
console.log(JSON.stringify(thrownError, null, 4));
console.log(JSON.stringify(this, null, 4));
},
如何调试? GET请求返回状态码200:OK。响应标题显示内容长度为22194,但我没有响应正文?我从控制台记录中获得的输出是:
"{
"readyState": 0,
"status": 0,
"statusText": "[Exception... \"Failure\" nsresult: \"0x80004005 (NS_ERROR_FAILURE)\" location: \"JS frame :: http://myownurl.com/jquery.js :: .send :: line 8526\" data: no]"
}"
""error""
"{}"
undefined
"{
"url": "http://targeturl.com/api/get?user=user1&password=password1&id=2",
"type": "GET",
"isLocal": false,
"global": true,
"processData": true,
"async": false,
"contentType": "application/x-www-form-urlencoded; charset=UTF-8",
"accepts": {
"*": "*/*",
"text": "text/plain",
"html": "text/html",
"xml": "application/xml, text/xml",
"json": "application/json, text/javascript",
"script": "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
"contents": {
"xml": {},
"html": {},
"json": {},
"script": {}
},
"responseFields": {
"xml": "responseXML",
"text": "responseText"
},
"converters": {
"text html": true
},
"flatOptions": {
"url": true,
"context": true
},
"jsonp": "callback",
"crossDomain": true,
"dataType": "xml",
"dataTypes": [
"xml"
],
"hasContent": false
}"
(我不确定它是否有任何区别,但我在FireFox中尝试这个)