开发者

How to reload page after .submit()

开发者 https://www.devze.com 2023-03-09 18:58 出处:网络
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.

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.

For example, my initial attempt:

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;
});

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消