Veeru A S Veeru A S - 6 months ago 19
Ajax Question

Prior statements not getting executed on sync ajax call

I have a function like

function m1(){
$('.loader').show();

var xargs={
type : 'POST',
url : resourceUrls["listUrl"],
data : "sId="+sId,
async:false,
dataType : "text",
success : OnGetJsonCallback,
failure : function(response) {
$(".loader").hide();
}

};

$.ajax(xargs);
}


here the problem, the loader is not getting shown before making ajax call. If I put a console log statement that is getting logged.

I did some searching and got to know that synchronous AJAX calls freeze the browser. But it can show the loader and then freeze the browser isnt it?

Answer

I did some searching and got to know that synchronous AJAX calls freeze the browser. But it can show the loader and then freeze the browser isnt it?

I disagree of doing this but you can listen to show complete and then make sync call :

$('.loader').show(500, m1);

function m1(){
   var xargs={
          type : 'POST',
          url : resourceUrls["listUrl"],
          data : "sId="+sId,
          async:false,
          dataType : "text",
          success : OnGetJsonCallback,
          failure : function(response) {
                 $(".loader").hide();
                 }

   };

  $.ajax(xargs);
}