Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax request in progress jQuery

Is there a way to check if there's ajax request in progress? Something like:

if ( $.ajax.inProgress ){ do this; } else { do that; }
like image 276
bah Avatar asked May 20 '10 09:05

bah


People also ask

How do I know when Ajax calls are complete?

The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.

How would you implement progress bar based on Ajax response?

Use the ajaxStart to start your progress bar code. $(document). ajaxStop(function(){ // hide the progress bar $("#progressDialog"). modal('hide'); });

How do I get Ajax request?

send = function() { console. log( arguments ); //Here is where you can add any code to process the request. //If you want to pass the Ajax request object, pass the 'pointer' below var pointer = this var intervalId = window. setInterval(function(){ if(pointer. readyState !=


2 Answers

If you are in full control of the javascript code you could increment a variable whenever you start an ajax request and decrement it when the request completes (with success, failure or timeout). This way you always know if there is a request in progress.

like image 112
kgiannakakis Avatar answered Sep 27 '22 02:09

kgiannakakis


yes there is


$.ajax({
     type: 'get',
     url: 'url',
     data: {
              email: $email.val()
     },
     dataType: 'text',
     success: function(data)
     {
        if(data == '1')
        {
            $response.attr('style', '')
                     .attr('style', "color:red;")
                     .html('Email already registered please enter a different email.');
        }
        else
        {
            $response.attr('style', '')
                     .attr('style', "color:green;")
                     .html('Available');
        }
     },
     beforeSend: function(){
                $email.addClass('show_loading_in_right')
     },
     complete: function(){
                $email.removeClass('show_loading_in_right')
     }
});


the beforeSend will do the process you need to do when the ajax request has just started and complete will be called when the ajax request is complete.
documentation

like image 33
Gaurav Sharma Avatar answered Sep 25 '22 02:09

Gaurav Sharma