【发布时间】:2012-07-13 00:29:22
【问题描述】:
我在链接上使用click函数通过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();
}
});
任何帮助将不胜感激。
【问题讨论】:
-
您的确切问题是什么?
-
我想他只是想通过 ajax 使用回车键提交表单。
-
@Daveo 想要在 jquery 验证中使用提交处理程序,但也使用提交链接...
标签: jquery submit form-submit jquery-validate