how to overwrite the success function via JQuery ajaxSend event

前端 未结 3 930
走了就别回头了
走了就别回头了 2021-01-05 12:45

I am trying to overwrite the success function upon ajaxsend event but it doesnt work here is the code:

    $(document).ajaxSend(function(event,xhr,options){
         


        
3条回答
  •  花落未央
    2021-01-05 13:19

    Because the option.success is used before ajaxSend. When it was used,it was added to the Deferred Object.

    After that,you change the option.success, nothing will happen.

    So, you must change it before is was used. the process is:

    $.ajaxPrefilter -- $.fn.ajaxStart(if needed) -- option.beforeSend -- 
    USE option.success and option.error and option.complete -- 
    $.ajaxTransport -- $.fn.ajaxSend -- send the actual request -- 
    option.dataFilter --  fire the success/error callbacks -- 
    $.fn.ajaxSuccess/$.fn.ajaxError -- fire the complete callbacks --  
    $.fn.ajaxComplete -- $.fn.ajaxStop(if needed)
    

    So, you can change the option.success in "$.ajaxPrefilter" or "option.beforeSend".

提交回复
热议问题