async:false option not working in $.ajax() , is it depreciated in jQuery 1.8+ for all use cases?

前端 未结 3 627
耶瑟儿~
耶瑟儿~ 2020-12-11 05:26

I\'m confused about using the async: false option with $.ajax(). According to the $.ajax() documentation:

As of jQuery 1.8, the use of async: false w

3条回答
  •  独厮守ぢ
    2020-12-11 06:18

    what it is saying is, if your request is async: false then you should not use ajax.done(), ajax.fail() etc methods to register the callback methods, instead you need to pass the callback methods using success/error/complete options to the ajax call

    correct

    $.ajax({
        async: false,
        success: function(){
        },
        error: function(){
        },
        complete: function(){
        }
    })
    

    wrong

    $.ajax({
        async: false
    }).done(function(){
    }).fail(function(){
    }).always(function(){
    })
    

    if async: true //not specified

    correct

    $.ajax({
    }).done(function(){
    }).fail(function(){
    }).always(function(){
    })
    

    or

    $.ajax({
        async: false,
        success: function(){
        },
        error: function(){
        },
        complete: function(){
        }
    })
    

提交回复
热议问题