admin管理员组文章数量:1336137
I have this code
$('#postinput').on('keyup',function(){
var txt=$(this).val();
$.ajax({
type: "POST",
url: "action.php",
data: 'txt='+txt,
cache: false,
context:this,
success: function(html)
{
alert(html);
}
});
});
$('#postinput2').on('keyup',function(){
var txt2=$(this).val();
$.ajax({
type: "POST",
url: "action.php",
data: 'txt2='+txt2,
cache: false,
context:this,
success: function(html)
{
alert(html);
}
});
});
Suppose user clicked on #postinput
and it takes 30 seconds to process.If in the meantime user clicks on #postinput2
. I want to give him an alert "Still Processing Your Previous request"
. Is there a way i can check if some ajax is still in processing?
Suppose I have lot of ajax running on the page. Is there a method to know if even a single one is in processing?
I have this code
$('#postinput').on('keyup',function(){
var txt=$(this).val();
$.ajax({
type: "POST",
url: "action.php",
data: 'txt='+txt,
cache: false,
context:this,
success: function(html)
{
alert(html);
}
});
});
$('#postinput2').on('keyup',function(){
var txt2=$(this).val();
$.ajax({
type: "POST",
url: "action.php",
data: 'txt2='+txt2,
cache: false,
context:this,
success: function(html)
{
alert(html);
}
});
});
Suppose user clicked on #postinput
and it takes 30 seconds to process.If in the meantime user clicks on #postinput2
. I want to give him an alert "Still Processing Your Previous request"
. Is there a way i can check if some ajax is still in processing?
Suppose I have lot of ajax running on the page. Is there a method to know if even a single one is in processing?
Share Improve this question edited Oct 29, 2013 at 13:19 Ace asked Oct 29, 2013 at 13:06 AceAce 84510 silver badges23 bronze badges 4- So, quick (and possibly dirty) idea of mine is: just use a global boolean "isProcessing" and set it to true/false while processing / in success method of ajax. Edit: Ok, now there's the same thing as an answer ;) – Dominik Commented Oct 29, 2013 at 13:10
- @Dominik tnx.. if i have a number of ajax on same page suppose 5. This true & false method won't work then. Is there any method to check if even 1 ajax is in progress..? – Ace Commented Oct 29, 2013 at 13:16
-
1
Just check
$.active
property. It's not mentioned in the official documentation, and it might change later, but currently it's covered by unit tests, hasn't changed since 2010 and even has some bug tracking attached. ) – raina77ow Commented Oct 29, 2013 at 13:19 - @raina77ow tnx $.active did the trick :) – Ace Commented Oct 29, 2013 at 13:27
1 Answer
Reset to default 6You can set a variable to true
or false
depending on when an AJAX call starts, example:
var ajaxInProgress = false;
$('#postinput2').on('keyup',function(){
var txt2=$(this).val();
ajaxInProgress = true;
$.ajax({
..
..
success: function(html) {
ajaxInProgress = false;
Now check it if you need to before a call:
if (ajaxInProgress)
alert("AJAX in progress!");
Or, use global AJAX events to set the variable
$( document ).ajaxStart(function() {
ajaxInProgress = true;
});
$( document ).ajaxStop(function() {
ajaxInProgress = false;
});
本文标签: javascriptCheck if some ajax on the page is in processingStack Overflow
版权声明:本文标题:javascript - Check if some ajax on the page is in processing? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742393564a2466466.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论