/**
* 提交表单
* 适用场景:form表单的提交,主要用在用户、角色、资源等表单的添加、修改等
* @param {Object} commitUrl 表单提交地址*/
functioncommit(formId, commitUrl) {//组装表单数据
varindex;var data = $("#" +formId).serialize();
$.ajax({
type:"POST",
url: commitUrl,
data: data,
dataType:"json",
success:function(resultdata) {if(resultdata.success) {
parent.layer.close(index);
layer.msg(resultdata.message, {icon:1, time: 2000});
setTimeout('window.parent.location.reload()', 1000);
}else{
layer.msg(resultdata.message, {icon:5});
}
},
error:function(data, errorMsg) {
layer.close(index);
layer.msg(data.responseText, {icon:2});
}
});
}/**
* 表单的删除
* @param url 删除地址
* @param id 删除id 如果是批量,可以不写*/
functionremove(url, id) {varselectList;if (id != null) {
selectList=id;
}else{
selectList= jQuery(".table tbody input[type=checkbox]:checked").map(function() {return jQuery(this).val();
}).get().join(',');
}if (selectList != null && selectList != '') {
layer.confirm('确认要删除吗?', function(index) {
$.ajax({
type:"POST",
url: url,
data: {"ids": selectList
},
dataType:"json",
success:function(resultdata) {if(resultdata.success) {
layer.msg(resultdata.message, {icon:1, time: 2000});
setTimeout('window.location.reload()', 1000);
}else{
layer.msg(resultdata.message, {icon:5});
}
},
error:function(errorMsg) {
layer.msg('服务器未响应,请稍后再试', {icon: 3});
}
});
});
}else{
layer.msg("你没有选择行", {icon: 0});
}
}