jquery ajax synchronous call beforeSend

前端 未结 3 563
时光取名叫无心
时光取名叫无心 2021-02-08 06:06

I have a function called:

function callAjax(url, data) {
 $.ajax(
   {
     url: url, // same domain
     data: data,
     cache: false,
     async: false, // us         


        
3条回答
  •  忘掉有多难
    2021-02-08 06:31

    This is what you are looking for - .ajaxStart()

    It will be triggered when any ajax event starts

    http://api.jquery.com/ajaxStart/

    They even give a specific example similar to what you are trying to accomplish:

     $("#loading").ajaxStart(function(){
       $(this).show();
     });
    

    You can then use the .ajaxStop() function

    $("#loading").ajaxStop(function(){
          $(this).hide();
    });
    

提交回复
热议问题