Reputation: 159
Can anyone help me..
i have this AJAX script calling a XML page.
$.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)
{
...
}
But i return status: 200 OK in the error object. Why is that happen?
Here i my console log:
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
The XML response is:
<?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>
Upvotes: 1
Views: 1897
Reputation: 2770
Okay, this is XML parsing issue. The XML you receive has unescaped ampersand character in line 25:
<comment>Inde hos Joe & The Juice</comment>
Ask the client to escape it or change it to text. The rest of the XML parses correctly.
Please check a similar issue here
Also, please remember to add such info to your question next time, it helps a lot. ;)
Upvotes: 2
Reputation: 7462
Use this type of callback to see proper error.
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
}
And then fix , by setting proper return data type.
This link might be helpful - jQuery AJAX 200 status, yet mysterious syntax error
Upvotes: 1