0

I am trying to show the loader during asynchronous call, but loader is not display. This is what i have done so far.

$.ajax({
        type : "POST",
        url : 'http://demo.co.in/projects/demo/webservice/',
        dataType : "json", 
        async : false, 
        beforeSend: function(){
                      $('#pageLoader').show( "slow", function() { }); 
                      $('#pageLoader').html('<img src="images/loader.gif" />');     
                    },
        success : function(data) {   
        }, 
        error : function(jqXHR, textStatus, errorThrown) {
            alert("Server timed out. Please try again.") 
        }  
    }); 

One thing i have notice so far, when i remove the async : false, from my code after that loader is display.

Rafael
  • 7,605
  • 13
  • 31
  • 46
user2380151
  • 151
  • 1
  • 1
  • 10
  • async option set to false is synchronous. delete that if you want asynchronous -- http://stackoverflow.com/questions/133310/how-can-i-get-jquery-to-perform-a-synchronous-rather-than-asynchronous-ajax-re -- i would delete the beforeSend: function(){ and put your loader above $.ajax({ – Tasos Jan 29 '15 at 02:34

2 Answers2

1

Javascript is single threading, you should use the async mode and make your code event driven.

Joerg
  • 3,102
  • 2
  • 24
  • 30
0

try

async : true,

by doing that you'll declare ajax call as asynchronous

AtanuCSE
  • 8,832
  • 14
  • 74
  • 112