Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 中止ajax调用?_Javascript_Jquery - Fatal编程技术网

Javascript 中止ajax调用?

Javascript 中止ajax调用?,javascript,jquery,Javascript,Jquery,My currentReq var设置为回调方法: this.currentReq = cb.apply(this,args); 稍后,如果是ajax调用,我可能希望中止该方法 我知道我可以使用: this.currentReq.abort(); 但是如果currentReq不是ajax调用呢?我如何测试它,并且只有在它是一个ajax调用时才中止?当我尝试在标准延迟上中止时,我收到一个错误。您可以首先测试中止方法是否存在: if (typeof(this.currentReq.abort)

My currentReq var设置为回调方法:

this.currentReq = cb.apply(this,args);
稍后,如果是ajax调用,我可能希望中止该方法

我知道我可以使用:

this.currentReq.abort();

但是如果currentReq不是ajax调用呢?我如何测试它,并且只有在它是一个ajax调用时才中止?当我尝试在标准延迟上中止时,我收到一个错误。

您可以首先测试
中止方法是否存在:

if (typeof(this.currentReq.abort) == "function") {
     this.currentReq.abort();
}

您可以首先测试
abort
方法是否存在:

if (typeof(this.currentReq.abort) == "function") {
     this.currentReq.abort();
}

如果错误指向未定义的方法,则应该能够测试函数本身是否存在

if(typeof this.currentReq.abort === 'function') {
    this.currentReq.abort();
}

如果错误指向未定义的方法,则应该能够测试函数本身是否存在

if(typeof this.currentReq.abort === 'function') {
    this.currentReq.abort();
}

一般来说,在这些情况下,你寻找的是一把“冒烟的枪”,只有你需要瞄准的枪有或已经设定了某个值。。。为什么不做经典的鸭子打字,看看它是否可以中止?除非您有其他可中止的调用,而这些调用不是您正在寻找的ajax调用。一般来说,在这些情况下,您会寻找一个“冒烟的枪”,只有您需要瞄准的那一个具有或已设置为特定值。相关的mmm。。。为什么不做经典的鸭子打字,看看它是否可以中止?除非您有其他可中止的调用,而这些调用不是您正在寻找的ajax调用。