任何人都可以帮助我..
我有这个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>
答案 0 :(得分:1)
好的,这是XML解析问题。您收到的XML在第25行中没有未转换的&符号:
<comment>Inde hos Joe & The Juice</comment>
要求客户escape it或将其更改为文字。 XML的其余部分正确解析。
请检查类似问题here
此外,请记得下次将此类信息添加到您的问题中,这会有很大帮助。 ;)
答案 1 :(得分:0)
使用此类型的回调查看正确的错误。
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
}
然后通过设置正确的返回数据类型来修复。
此链接可能会有所帮助 - jQuery AJAX 200 status, yet mysterious syntax error