admin管理员组文章数量:1188830
i am making a ajax request using $.get as soon as the user types a character in the input box i want to abort the previous ajax calls and then make the new one, is there a way?
edit
solved!
i just found out that $.get is a shorthand way to $.ajax and hence it returns a XHR and so we can call abort on that variable.
i am making a ajax request using $.get as soon as the user types a character in the input box i want to abort the previous ajax calls and then make the new one, is there a way?
edit
solved!
i just found out that $.get is a shorthand way to $.ajax and hence it returns a XHR and so we can call abort on that variable.
Share Improve this question edited Nov 12, 2010 at 10:55 Shaheer asked Nov 12, 2010 at 10:50 ShaheerShaheer 2,1474 gold badges25 silver badges39 bronze badges 1- possible duplicate of jquery abort() ajax request before sending another – Pekka Commented Nov 12, 2010 at 10:55
1 Answer
Reset to default 30You can use .abort()
on XMLHttpRequest that $.get
returns.
var req = $.get('ajax/test.html', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
//Abort request
req.abort()
From jQuery.ajax() documentation:
The $.ajax() function returns the XMLHttpRequest object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the xhr option. The returned object can generally be discarded, but does provide a lower-level interface for observing and manipulating the request. In particular, calling .abort() on the object will halt the request before it completes.
More on .abort()
: XMLHttpRequest.abort()
There is also jQuery plugin AjaxQueue for handling multiple Ajax request made in parallel.
本文标签: how to stop jquery ajax request sent via getStack Overflow
版权声明:本文标题:how to stop jquery ajax request sent via $.get? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738383056a2084046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论