1、首先引入jquery.form.min.js文件
2、
function onSubmit(){
var url='<%=path %>/before/beforeInfo_saveInfo.do?type=<%=request.getAttribute("disType")%>';
var options = {
//target: '#output1',// target element(s) to be updated with server response
beforeSubmit: showRequest,// pre-submit callback
success: showResponse,// post-submit callback
// other available options:
url: url,// override for form's 'action' attribute
type: 'post',// 'get' or 'post',override for form's 'method' attribute
dataType: 'json',// 'xml','script',or 'json' (expected server response type)
clearForm: true,// clear all form fields after successful submit
resetForm: true // reset the form after successful submit
// $.ajax options can be used here too,for example:
//timeout: 3000
};
// bind form using 'ajaxForm'
$('#validForm').ajaxForm(options);
}
function showRequest(formData,jqForm,options) { //在提交之前可以用来校验所填写的信息。 //var queryString = $.param(formData); //alert('About to submit: \n\n' + queryString); var title = $.trim($('#title').val()); if(""==title){ alert("请填写标题!"); return false; } var keyWord = $.trim($('#keyWord').val()); if(""==keyWord){ alert("请填写关键字!"); return false; } var editorDescs = $.trim(UE.getEditor('editorDescs').getContent()); if(""==editorDescs){ alert("请填写问题描述!"); return false; } var editorSolution = $.trim(UE.getEditor('editorSolution').getContent()); if(""==editorSolution){ alert("请填写解决方案!"); return false; } var area = $('#scopeAreaId').val(); if("0"==area){ alert("请选择可查询区域!"); return false; } return true; }
function showResponse(responseText,statusText,xhr,$form) { //相应结束之后返回json串,并继续处理。 if('success'==responseText.msg){ var infoId = responseText.infoId; var url = '<%=path %>/before/beforeInfo_toAddAreaScope.do?infoId='+infoId; var rs = showModalDlg(url,'',500,150); if(rs==1){ alert("发布成功!"); }else{ alert("发布失败!"); } location.href='<%=path %>/before/beforeInfo_toInfoMgrList.do?type=<%=request.getAttribute("disType")%>'; } }