jquery ajax synchronous call beforeSend

前端 未结 3 500
时光取名叫无心
时光取名叫无心 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:40

    When you do the blocking I/O the program is halted until the the input is received, in JS words when doing a synchronous call, the program halts and browser window freezes (no painting can be done) until the response is received. In most cases doing syncronus calls and any kind of blocking I/O can be avoided. However imagine your doing a progress bar in java or any other programming language, you have to spawn a different thread to control the progress bar, I think.

    One thing to try in your case, is to call the ajax call after a time delay

    //loading div stuff, 
    //if your doing some animation here make sure to have Sufficient 
    //time for it. If its just a regular show then use a time delay of 100-200
    setTimeout( ajaxCall, 500 );
    

    EDIT ajaxcall in setTimeout, Example

提交回复
热议问题