这个$ .post ajax电话有什么问题?

Ism*_*ilp 2 ajax jquery

我发布了一个表单vi jQuery的$ .post,这是我的代码:

function onSuccess() {
    // Do something onSuccess
    alert('yep');
}

$('#createUserForm').submit( function(){
    $.post("test.php", $(this).serialize(), onSuccess()) 
});
Run Code Online (Sandbox Code Playgroud)

为什么浏览器会提醒"yep"然后重新加载页面?!

谢谢!

Nea*_*eal 5

一件事:

$.post("test.php", $(this).serialize(), onSuccess); //<--remove the ()
Run Code Online (Sandbox Code Playgroud)

其次,禁用默认操作:

$('#createUserForm').submit( function(e){
    e.preventDefault();
    $.post("test.php", $(this).serialize(), onSuccess);
    return false;
});
Run Code Online (Sandbox Code Playgroud)