How do I resend a failed ajax request?

前端 未结 4 1085
不知归路
不知归路 2020-11-27 07:20

I have multiple ajax requests some request data every minute others are initiated by the user through a ui.

$.get(\'/myurl\', data).done(function( data ){
           


        
4条回答
  •  悲哀的现实
    2020-11-27 07:45

    The code below will keep the original request and it will try to success 3 times.

    var tries = 0;
    $( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {
        if(tries < 3){
            tries++;
            $.ajax(this).done(function(){tries=0;});
        }
    });
    

提交回复
热议问题