我是AJAX新手。使用ajax提交表單並留在註冊頁面
我試圖提交與阿賈克斯形式使用以下邏輯:
//validate form
//if invalid never submit
//if valid, ajax request to get msg
//get success html if no server side errors exist. Replace sign up page with success html
//get fail message if server side errors exist, so the user can correct them (ex. invalid credit card no)
我的AJAX:
$("form").submit(function(e){
if($(this).valid()) {
$.ajax({
url: 'formAction.php',
type: 'POST',
success: function(data){
/*convert php variables to JavaScript ones*/
if(success==true){
//relpace current page with confirmation
}
if(success==false){
//print out errors and allow user to re-submit
}
}
});
}
e.preventDefault;
});
如果我在正確的軌道與此實現上我想知道?或者如果這種實現甚至是可能的?
我非常感謝任何建議,使這個實施工作。
非常感謝提前!
你在正確的軌道上,但你需要獲取你的表單數據到一個JavaScript變量來使用你['$ .post'](http://api.jquery.com/jQuery。 post /)並添加'data:myFormData' – Jon 2013-04-07 18:15:16