如何后.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 s...

我要成功登录,即$。员额()是否返回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.

阅读全文

相关推荐

最新文章