我使用链接上的点击功能通过ajax提交表单,如果服务器返回错误,则显示服务器端错误。jquery验证提交 - 使用ajax提交 - 点击功能
使用这种方法,回车键不起作用的形式,我认为这可能是一个更容易和更正确的方式来做到这一点与jQuery验证的提交处理程序。
这里是到目前为止我的代码...
function loginSubmit(){
$.ajax({
url: loginFormURL,
type: 'POST',
/** contentType: "application/json;", **/
dataType:"text json",
/** async: true, **/
data:$('#loginForm').serialize(),
success: function(data){
if(data.isError == "false" || data.isError == ""){
$.postMessage(
'redirectURL|'+ redirectURL +'',
'*',
parent
);
} else
if(data.isError == "true"){
$("#loginError").empty().show();
// iterate over the message list and display the error
for (var i=0; i < data.errorMessages.length; i++){
// inject error message to the error container
$("#loginError").append(data.errorMessages[i]);
}
// iterate over the field list and paint the fields in red
$('input').parent('div').addClass('inputError');
}
}
});
}
和点击功能:
$("a#loginButton").click(function(){
$("#loginForm").validate().form(this);
if($('#loginForm').valid()){
loginSubmit();
}
});
任何帮助,将不胜感激。
你确切的问题是什么? – Daveo 2012-07-13 00:34:18
我想他只是想通过使用回车键的ajax提交表单。 – 2012-07-13 00:46:26
@Daveo想要利用jQuery验证中的submithandler,但也使用链接提交... – Jason 2012-07-13 01:30:12