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

时间:2012-09-10 21:30:41

标签: jquery ajax

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

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

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

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

谢谢!

1 个答案:

答案 0 :(得分:5)

一方面:

$.post("test.php", $(this).serialize(), onSuccess); //<--remove the ()

其次,禁用默认操作:

$('#createUserForm').submit( function(e){
    e.preventDefault();
    $.post("test.php", $(this).serialize(), onSuccess);
    return false;
});
相关问题