[英]jQuery form plugin - abort request
I am trying to abort a jQuery form plugin ajax request. 我试图中止jQuery表单插件ajax请求。
NOTE: I am talking about this plugin http://jquery.malsup.com/form , not $.ajax()
注意:我说的是这个插件http://jquery.malsup.com/form ,而不是$.ajax()
I generally do this to abort $.ajax()
request: 我通常这样做是为了中止$.ajax()
请求:
if(typeof this.query !== 'undefined'){
this.query.abort();
}
this.query = jQuery.ajax({
...
...
});
but with jQuery from plugin , this does not work. 但是使用插件中的jQuery ,这不起作用。 I seen some solutions on SO, which uses beforeSend
to abort, but that solution will not work for me. 我在SO上看到了一些解决方案,它使用beforeSend
来中止,但是这个解决方案对我来说不起作用。
I want to check if ajax request running for same form, then abort previous request before sending new request. 我想检查ajax请求是否运行相同的表单,然后在发送新请求之前中止先前的请求。
Please suggest a way to abort jQuery from request. 请建议一种从请求中止jQuery的方法。
Thanks 谢谢
You can access the xhr
from the malsup form and abort the request like so: 您可以从malsup表单访问xhr
并中止请求,如下所示:
var form = $('#myForm').ajaxSubmit({ ... });
var xhr = form.data('jqxhr');
xhr.abort();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.