jQuery Refresh/Reload Page if Ajax Success after time

前端 未结 7 586
心在旅途
心在旅途 2020-12-14 02:42

I use Jquery to make an Ajax request. The server returns Json object with value "true or false" like this:

return Json(new { success = false, JsonRe         


        
7条回答
  •  一整个雨季
    2020-12-14 03:27

    In your ajax success callback do this:

    success: function(data){
       if(data.success == true){ // if true (1)
          setTimeout(function(){// wait for 5 secs(2)
               location.reload(); // then reload the page.(3)
          }, 5000); 
       }
    }
    

    As you want to reload the page after 5 seconds, then you need to have a timeout as suggested in the answer.

提交回复
热议问题