整合ajax方法
不需重复编写一些重复的ajax参数
var hajax = (hajax || function () {
var h = {},
option = {
//以下整合再修改
dataType: "jsonp",
jsonpCallback: "callback",
crossDomain: true,
url: "http://localhost:8080"
},
ajaxOption = {
type: "get",
cache: "false",
contentType: "application/json;charset=utf-8",
},
submitOption = {
type: "post",
contentType: false,
processData: false,
}
h.ajax = function (url, opt) {
opt || (opt = {});
opt.url = option.url + url;
$.ajax($.extend({}, ajaxOption, option, opt));
}
h.ajaxSubmit = function (url, opt) {
opt || (opt = {});
opt.url = option.url + url;
$.ajax($.extend({}, submitOption, option, opt));
}
return h;
}());
使用
hajax.ajax("mArchive/ setMaintainArchive.do",{
data : {
maintain_time: date,
hardware_change: yjbd,
software_change: rjbd,
parameter_setting : cssz,
file: nfile
},
success:function (data) {
// 接收后端传回信息
//Error: 提示保存失败,失败原因:?
if(data.state == "error"){
alert("保存失败")
}
if(data.state == "success"){
//Success:提示保存成功,并返回维护档案列表页
window.location.href = "whda.html";
}
},
error:function (data) {
alert("保存失败")
}
});