任何人都可以幫助我..阿賈克斯請求返回200好,但錯誤,而不是成功
我有這個AJAX腳本調用一個XML頁面。
$.ajax({
type: "GET",
url: "game/",
dataType: "xml",
data : {
g : 'new',
uid : uid
},
error: function (xml) {
console.log("ERROR");
console.log(xml);
alert(xml.status + ' ' + xml.statusText)
},
success: function(xml)
{
...
}
但是我在錯誤對象中返回狀態:200 OK。爲什麼會發生?
在這裏,我我的控制檯日誌:
ERROR speedywebs.js:678
Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}abort: function (e){var t=e||S;return f&&f.abort(t),N(0,t),this}always: function(){return i.done(arguments).fail(arguments),this}complete: function(){if(a){var t=a.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);r==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&r!=="string"&&i(n)})})(arguments),n?s=a.length:r&&(u=t,l(r))}return this}done: function(){if(a){var t=a.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);r==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&r!=="string"&&i(n)})})(arguments),n?s=a.length:r&&(u=t,l(r))}return this}error: function(){if(a){var t=a.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);r==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&r!=="string"&&i(n)})})(arguments),n?s=a.length:r&&(u=t,l(r))}return this}fail: function(){if(a){var t=a.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);r==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&r!=="string"&&i(n)})})(arguments),n?s=a.length:r&&(u=t,l(r))}return this}getAllResponseHeaders: function(){return w===2?o:null}getResponseHeader: function (e){var t;if(w===2){if(!l){l={};while(t=Sn.exec(o))l[t[1].toLowerCase()]=t[2]}t=l[e.toLowerCase()]}return t==null?null:t}overrideMimeType: function (e){return w||(c.mimeType=e),this}pipe: function(){var e=arguments;return b.Deferred(function(n){b.each(t,function(t,s){var o=s[0],u=b.isFunction(e[t])&&e[t];i[s[1]](function(){var e=u&&u.apply(this,arguments);e&&b.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o+"With"](this===r?n.promise():this,u?[e]:arguments)})}),e=null}).promise()}progress: function(){if(a){var t=a.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);r==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&r!=="string"&&i(n)})})(arguments),n?s=a.length:r&&(u=t,l(r))}return this}promise: function (e){return e!=null?b.extend(e,r):r}readyState: 4responseText: "<?xml version="1.0" encoding="UTF-8"?><cards><card1><id>119</id><download>19.99</download><upload>12.48</upload><ping>24</ping><testserver>Stockholm 2</testserver><hostname>x1-6-28-c6-8e-96-b1-da.cpe.webspeed.dk</hostname><name>@risager</name><location>Vangede</location><connection>Kabel/Fiber</connection><comment></comment></card1><card2><id>171</id><download>-</download><upload>-</upload><ping>-</ping><testserver>Stockholm 2</testserver><hostname>94.191.184.222.mobile.3.dk</hostname><name>@camillaBandit</name><location>København K</location><connection>4G/LTE</connection><comment>Inde hos Joe & The Juice</comment></card2></cards>"setRequestHeader: function (e,t){var n=e.toLowerCase();return w||(e=y[n]=y[n]||e,g[e]=t),this}state: function(){return n}status: 200statusCode: function (e){var t;if(e)if(w<2)for(t in e)m[t]=[m[t],e[t]];else x.always(e[x.status]);return this}statusText: "OK"success: function(){if(a){var t=a.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);r==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&r!=="string"&&i(n)})})(arguments),n?s=a.length:r&&(u=t,l(r))}return this}then: function(){var e=arguments;return b.Deferred(function(n){b.each(t,function(t,s){var o=s[0],u=b.isFunction(e[t])&&e[t];i[s[1]](function(){var e=u&&u.apply(this,arguments);e&&b.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[o+"With"](this===r?n.promise():this,u?[e]:arguments)})}),e=null}).promise()}__proto__: Object
XML響應是:
<?xml version="1.0" encoding="UTF-8"?><cards><card1><id>119</id><download>19.99</download><upload>12.48</upload><ping>24</ping><testserver>Stockholm 2</testserver><hostname>x1-6-28-c6-8e-96-b1-da.cpe.webspeed.dk</hostname><name>@risager</name><location>Vangede</location><connection>Kabel/Fiber</connection><comment></comment></card1><card2><id>171</id><download>-</download><upload>-</upload><ping>-</ping><testserver>Stockholm 2</testserver><hostname>94.191.184.222.mobile.3.dk</hostname><name>@camillaBandit</name><location>København K</location><connection>4G/LTE</connection><comment>Inde hos Joe & The Juice</comment></card2></cards>
錯誤回調的第三個參數包含了什麼?解析錯誤? – 2014-10-10 18:13:35
只是一個方面的評論,也許增加一個「完整的」回調以及檢查完整回調的textStatus。 ' – 2014-10-10 18:14:29
your xml is invalid。' Inde hos Joe&...'應該是' Inde hos Joe & ...'或者將字符串包裝在CDATA中 –
2014-10-10 18:14:51