ajaxJson(常用)

function ajaxJson(method, url, data, callback) {
var options = {
type: method,
url: url,
dataType: 'JSON',
traditional: true,
contentType: "application/json; charset=utf-8"
};
if (typeof data === 'function') { // No data offered
callback = data;
} else { // Add data
options.data = data;
}
options.success = function (msg) {
return callback(null, msg);
};
options.error = function (err) {
return callback(err);
};
$.ajax(options);
}

  

ajaxJson('POST', url, JSON.stringify(param), function(err, result){
  //result or rsp

  // if(SUCCESS){

  //.......  

  }else{

  //.......

  }
});

——————————————————————————————————————————————————————————————————————

//DateTables (ajax) 异步获取数据填充到表格显示(ajax)

        ajax: function (data, callback, settings) {
//封装请求参数
var param = {
"page": { }
};
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(param),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
//......
callback(returnData);
}
});
}

  _____________________________________________________________________________________________________________________________

    var options = {
url: url,
type: 'POST',
data: data,
processData: false,
contentType: false,
success: function (rsp) {
if(rsp.code==200){
....
}else{
....
}
},
error: function (e) {
//......
}
};
$.ajax(options);

  //----------------------------------------

    $.ajax({
type: "POST",
url: webroot + "/ht/uploadAndSaveFile",
data: JSON.stringify(params),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(rsp) {
console.log(rsp)
// if (rsp.code == 200) {
// if (paramsId == '') {
// hint("添加成功");
// } else {
// hint("修改成功");
// }
// $("#addCustomerBox").modal("hide");
// //getCustomerList(1);
// loadTalbe();
// clearCustomer();
// } else {
// hint(rsp.message);
// };
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(rsp)
}
});
上一篇:安装J2EE的SDK报错:could not find the required version of the Java(TM)2 Runtime Environment in '(null)'的解决办法。


下一篇:关于在biweb 中安装完成后 首页上方报错问题的解决