如果Ajax在一段时间后成功,则jQuery刷新/重新加载页面 [英] jQuery Refresh/Reload Page if Ajax Success after time
本文介绍了如果Ajax在一段时间后成功,则jQuery刷新/重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Jquery来调用Ajax.服务器返回Json对象,其值为"true或false",如下所示:
I use Jquery to call Ajax. The server returns Json object with value "true or false" like this:
return Json(new { success = false, JsonRequestBehavior.AllowGet });
如果服务器返回true,是否可以在5秒后刷新页面?
Is there any way to refresh page after 5 seconds if the server returns true?
推荐答案
在ajax成功回调中执行以下操作:
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);
}
}
要在5秒钟后重新加载页面,则需要按照答案中的建议进行超时.
As you want to reload the page after 5 seconds, then you need to have a timeout as suggested in the answer.
这篇关于如果Ajax在一段时间后成功,则jQuery刷新/重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文