Jquery serialize()可以将form中参数格式化,用于ajax传参。
jQuery.ajax({
url: url, // 提交的页面
data: $("#" + formId).serialize(), // 从表单中获取数据
type: "POST", // 设置请求类型为"POST",默认为"GET"
dataType: "json",
contentType: "application/x-www-form-urlencoded;charset=UTF-8", // 必须要设置为UTF-8,否则提交数据乱码
beforeSend: function(){
if(!isunlock){
new screenClass().lock();
}
},
error: function(msg) { // 设置表单提交出错
new screenClass().unlock();
alert("执行出错:" + msg.responseText);
},
success: function(resp) {
if(!isunlock){
new screenClass().unlock(); // 设置表单提交完成使用方法
}
if(resp.success == false){
alert("执行失败:" + resp.resultMsg);
}else if(resp.success == true){
if(succback == '' || typeof(succback) == "undefined"){
window.location.href="success.jsp";
}else{
succback(resp.attributes);
}
}else{
alert("未知结果:" + resp);
}
},
cache: false
});