在处理表单提交后,有一个正在调用的函数。我正在使用JQuery 1.8和jquery.validate。
我有以下功能来检查并处理对服务器的调用并收到JSON成功回调:
<input type="submit" value="Continue"
name="submit_first" onclick="verifyPge();" />
这是我需要添加加载页面的功能,它需要在同一窗口中加载(JQuery加载页面) 此函数使用jquery.validate运行UI检查,我需要向此verifyPge()添加一个新函数;函数,以便表单加载新页面。使用方法或操作不是一个选项,并且在表单ID上调用验证以使其保持独立 // JavaScript文档 $()。ready(function(){
// validate signup form on keyup and submit
$("#yourInfo").validate({
rules: {
month: {
required: true,
},
day: {
required: true,
},
year: {
required: true
},
},
messages: {
month: {
required: "Please select the month you were born",
},
day: {
required: "Please select the day you were born",
},
year: {
required: "Please select the year you were born",
},
errorElement: "div"
}
});
});
有什么想法吗?基本上,在UI验证完成并处理表单之后,我想加载新页面但是使用JQuery Page加载并让Jquery通过Ajax切换页面。
答案 0 :(得分:0)
确保返回服务器中的网址
// document DOM ready
$(function() {
// validate signup form on keyup and submit
$("#yourInfo").validate({
submitHandler: function(form){
// submit the form via ajax
$.post(
// your script
'script.php',
// your form in a serialized way your server can understand
form.serializeArray()[0],
// success function
function(url){
window.location.assign(url); // load the new URL
}
);
return false;
},
rules: {
month: {
required: true,
},
day: {
required: true,
},
year: {
required: true
},
},
messages: {
month: {
required: "Please select the month you were born",
},
day: {
required: "Please select the day you were born",
},
year: {
required: "Please select the year you were born",
},
errorElement: "div"
}
});
});
jQuery validate插件已处理您的表单提交,无需在提交按钮中添加verifyPage()
。在验证表单后,使用submitHandler
是正确的提交方式。