Может ли кто-нибудь мне помочь ..Ajax request return 200 OK, но ошибка вместо успеха
У меня есть этот скрипт 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>
В чем состоит третий параметр обратного вызова ошибки? parseerror? –
Просто побочный комментарий, возможно, добавьте «полный» обратный вызов и проверьте текстСтатус полного обратного вызова. Кроме того, у вас довольно странный случай :( –
ваш xml недействителен. ' Inde hos Joe & ...' должно быть ' Inde hos Joe & ...' или обернуть строки в CDATA. –