jQuery ajax Page Reload

前端 未结 4 1125
我寻月下人不归
我寻月下人不归 2020-12-18 11:44

We are making multiple ajax requests to \"save\" data in a web app, then reload the page. We have run into a situation where (since requests are made asynchronously) the pa

4条回答
  •  误落风尘
    2020-12-18 12:30

    it depends on way you do your requests For example (you don't do form submit. Otherwise you need prevent form submission)

    $.ajax({
       url: 'some_url',
       type:    'GET',
       data: 'var1=value1&var2=value2',
     success: function(){
       //do smth
     },
     error: function(){
       alert(w.data_error);
       document.location.reload(); 
     }
     complete: function(){ //A function to be called when the request finishes (after success and error callbacks are executed) - from jquery docs
       //do smth if you need
       document.location.reload(); 
     }
    });
    

    Take a look onto complete block

提交回复
热议问题