我想知道是否有办法在 ZeptoJS 中中止 AJAX 调用,就像我.abort()
在 jQuery 中使用的一样。
我已经尝试过了,但我不断收到此错误:
Uncaught TypeError: Object #<t> has no method 'abort'
这是 AJAX 调用的样子:
SITE.Address.pendingZipLookup = $.ajax({
url: '/us/en-us/services/globalization/getcitysuggestions',
data: {"ZipCode" : newZipCode},
type: 'POST',
success: function (data) {
if(SITE.Address.suppressZipLookup) return;
if(data.length === 0) {
SITE.Navigation.showModal( SITE.TextTranslations.address.noAddressText , SITE.TextTranslations.address.noAddressHeading );
} else if(data.length == 1) {
SITE.Address.fillAddressElm($addressFormItem, data[0]);
} else {
SITE.Navigation.showModal( Mustache.to_html( $tmplSelectCity.html(), {Cities: data} ) , SITE.TextTranslations.address.selectCity );
$('.modal').find('.modal-header .buttonClose').one('click', clearForm).end();
}
},
error: function() {}
});
我正在调用.abort()
变量:
if ( SITE.Address.pendingZipLookup !== null && SITE.Address.pendingZipLookup.readyState !== 4 ) {
console.log(SITE.Address.pendingZipLookup.readyState);
SITE.Address.pendingZipLookup.abort();
}
既不.readyState
评估,它只是undefined
在控制台中返回。
编辑:这是SITE.Address.pendingZipLookup
登录控制台时的外观:
t {_deferred: e}
_deferred: e
_context: Window
_promise: t
_state: "resolved"
_withArguments: Array[3]
always: function (){return n.apply(t,arguments)}
done: function (){return n.apply(t,arguments)}
fail: function (){return n.apply(t,arguments)}
notify: function (){return n.apply(t,arguments)}
notifyWith: function (){return n.apply(t,arguments)}
pipe: function (){return n.apply(t,arguments)}
progress: function (){return n.apply(t,arguments)}
promise: function (){return n.apply(t,arguments)}
reject: function (){return n.apply(t,arguments)}
rejectWith: function (){return n.apply(t,arguments)}
resolve: function (){return n.apply(t,arguments)}
resolveWith: function (){return n.apply(t,arguments)}
then: function (){return n.apply(t,arguments)}
__proto__: e
always: function (){var t,i,u,f=this;return(t=1<=arguments.length?n.call(arguments,0):[],t.length===0)?this:(i=r(t),this._state==="pending"?(this._alwaysCallbacks||(this._alwaysCallbacks=[]),(u=this._alwaysCallbacks).push.apply(u,i)):i.forEach(function(n){return n.apply(f._context,f._withArguments)}),this)}
constructor: function e(n){this.then=t(this.then,this),this.resolveWith=t(this.resolveWith,this),this.resolve=t(this.resolve,this),this.rejectWith=t(this.rejectWith,this),this.reject=t(this.reject,this),this.promise=t(this.promise,this),this.progress=t(this.progress,this),this.pipe=t(this.pipe,this),this.notifyWith=t(this.notifyWith,this),this.notify=t(this.notify,this),this.fail=t(this.fail,this),this.done=t(this.done,this),this.always=t(this.always,this),this._state="pending",typeof n=="function"&&n.call(this,this)}
done: function (){var t,i,u,f=this;return(t=1<=arguments.length?n.call(arguments,0):[],t.length===0)?this:(i=r(t),this._state==="resolved"?i.forEach(function(n){return n.apply(f._context,f._withArguments)}):this._state==="pending"&&(this._doneCallbacks||(this._doneCallbacks=[]),(u=this._doneCallbacks).push.apply(u,i)),this)}
fail: function (){var t,i,u,f=this;return(t=1<=arguments.length?n.call(arguments,0):[],t.length===0)?this:(i=r(t),this._state==="rejected"?i.forEach(function(n){return n.apply(f._context,f._withArguments)}):this._state==="pending"&&(this._failCallbacks||(this._failCallbacks=[]),(u=this._failCallbacks).push.apply(u,i)),this)}
notify: function (){var t;return t=1<=arguments.length?n.call(arguments,0):[],this.notifyWith.apply(this,[i].concat(n.call(t))),this}
notifyWith: function (){var t,i,r;return(i=arguments[0],t=2<=arguments.length?n.call(arguments,1):[],this._state!=="pending")?this:((r=this._progressCallbacks)!=null&&r.forEach(function(n){return n.apply(i,t)}),this)}
pipe: function (t,i){var r;return r=new e,this.done(function(){var u,i,e;return u=1<=arguments.length?n.call(arguments,0):[],t!=null?(i=t.apply(this,u),f(i)?i.done(function(){var t,i;return t=1<=arguments.length?n.call(arguments,0):[],(i=r.resolveWith).call.apply(i,[r,this].concat(n.call(t)))}).fail(function(){var t,i;return t=1<=arguments.length?n.call(arguments,0):[],(i=r.rejectWith).call.apply(i,[r,this].concat(n.call(t)))}):r.resolveWith.call(r,this,i)):(e=r.resolveWith).call.apply(e,[r,this].concat(n.call(u)))}),this.fail(function(){var t,u,e,o;return t=1<=arguments.length?n.call(arguments,0):[],i!=null?(u=i.apply(this,t),f(u)?u.done(function(){var t,i;return t=1<=arguments.length?n.call(arguments,0):[],(i=r.resolveWith).call.apply(i,[r,this].concat(n.call(t)))}).fail(function(){var t,i;return t=1<=arguments.length?n.call(arguments,0):[],(i=r.rejectWith).call.apply(i,[r,this].concat(n.call(t)))}):r.rejectWith.call(r,this,u),(e=r.rejectWith).call.apply(e,[r,this].concat(n.call(t)))):(o=r.rejectWith).call.apply(o,[r,this].concat(n.call(t)))}),r.promise()}
progress: function (){var t,i,u;return(t=1<=arguments.length?n.call(arguments,0):[],t.length===0||this._state!=="pending")?this:(i=r(t),this._progressCallbacks||(this._progressCallbacks=[]),(u=this._progressCallbacks).push.apply(u,i),this)}
promise: function (){return this._promise||(this._promise=new u(this))}
reject: function (){var t;return t=1<=arguments.length?n.call(arguments,0):[],this.rejectWith.apply(this,[i].concat(n.call(t))),this}
rejectWith: function (){var t,i,r,u,f=this;return(i=arguments[0],t=2<=arguments.length?n.call(arguments,1):[],this._state!=="pending")?this:(this._state="rejected",this._withArguments=t,this._context=i,(r=this._failCallbacks)!=null&&r.forEach(function(n){return n.apply(f._context,t)}),(u=this._alwaysCallbacks)!=null&&u.forEach(function(n){return n.apply(f._context,t)}),this)}
resolve: function (){var t;return t=1<=arguments.length?n.call(arguments,0):[],this.resolveWith.apply(this,[i].concat(n.call(t))),this}
resolveWith: function (){var t,i,r,u,f=this;return(i=arguments[0],t=2<=arguments.length?n.call(arguments,1):[],this._state!=="pending")?this:(this._state="resolved",this._context=i,this._withArguments=t,(r=this._doneCallbacks)!=null&&r.forEach(function(n){return n.apply(f._context,t)}),(u=this._alwaysCallbacks)!=null&&u.forEach(function(n){return n.apply(f._context,t)}),this)}
state: function (){return this._state}
then: function (n,t,i){return this.done(n),this.fail(t),this.progress(i),this}
__proto__: Object
如果它看起来很奇怪,那是因为我复制了我在控制台中得到的对象,如果有更好的打印结果的方法,有人应该让我知道:)