我对ajax很新,所以我很惊讶这在IE7 / 8中对我来说不起作用或出错。但在其他浏览器中工作。这是一个验证脚本,用于验证表单内容,然后提交表单。成功后,它会更新页面:
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.6.2");
</script>
<script src="/javascripts/jquery.validate.js"></script>
<script src="/javascripts/jquery.form.js"></script>
[在文件就绪功能中]
// prepare the form when the DOM is ready
if ($("#contact_form").exists()){
$("#contact_form").validate();
// bind form using ajaxForm
$("#contact_form").ajaxForm({
beforeSubmit:function() {
return $("#contact_form").valid()
},
// target identifies the element(s) to update with the server response
target: "#success",
// success identifies the function to invoke when the server response
// has been received; here we apply a fade-in effect to the new content
success: function() {
$(".form-fields").hide();
$("#success").fadeIn("slow");
}
});
}
提前致谢!它确实提交了表单,但没有使用ajax或进行任何错误验证。