如何后.submit重新加载页面() [英] How to reload page after .submit()
本文介绍了如何后.submit重新加载页面()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要成功登录,即$。员额()是否返回1页应该重装后重新载入我的网页,并为0它不应该。
I want to reload my page after successful login i.e. whether $.post() returns a 1 page should reload and for a 0 it shouldn't.
例如,我最初的尝试:
var logon = false;
$('#formname').submit(function() {
$.post('load.php', $('#formname').serialize(), function(data) {
if(data == '0')
logon = false;
else
logon = true;
});
return logon;
});
我怎样才能做到这一点?
How can I do this?
推荐答案
您可以使用 重装()
方式:
You could use the reload()
method:
$('#formname').submit(function() {
$.post('load.php', $('#formname').serialize(), function(data) {
if(data == '1') {
window.location.reload();
}
});
return false;
});
我特意删除了登录
变量,因为它是没有必要的。 AJAX是异步的,所以退回此变量从提交处理程序是无用的,因为它不会被分配一个值呢。
I've intentionally removed the logon
variable as it is not needed. AJAX is asynchronous so returning this variable from the submit handler is useless because it won't be assigned a value yet.
这篇关于如何后.submit重新加载页面()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文