jQuery ajax beforeSend

后端 未结 4 647
遇见更好的自我
遇见更好的自我 2020-12-08 10:48

I have a simple AJAX call that is executing a function on the beforeSend and on complete. They execute fine but the beforeSend is \"se

4条回答
  •  轮回少年
    2020-12-08 11:17

    This is most probably because of async : false. As your call is synchronous, after your call to the $.ajax() function begins, nothing happens until the response is received, and the next thing as far as your code goes will be the success handler

    To make it work, You can do something like this

    $.blockUI({
            fadeIn : 0,
            fadeOut : 0,
            showOverlay : false
    });
    // and here goes your synchronous ajax call
    $.ajax({
                type : 'POST',
                url : url,
                async : false,
                data : postData,
                success : function (returnData) {
                    //stuff
                },
                error : function (xhr, textStatus, errorThrown) {
                    //other stuff
                },
                complete : function (){
                    $.unblockUI();
                }
         });
    

提交回复
热议问题