function ajaxData(url, data, flag=‘insertHtml’, method=‘POST’){
$.ajax({
type: method, //默认post
url: url, //默认当前页
data: data, //格式{key:value}
dataType: “json”,
success: function (ret) { //请求成功回调
if(ret.code == 200){
eval(flag+‘(ret)’);
}
},
error: function (e) { //请求超时回调
if(e.statusText == “timeout”){
alert(“请求超时”)
}
},
})
}
引用:
ajaxData(“www.url.com/list?type=1”, { }, ‘getListData’);
function getListData(ret){
console.log(ret.data);
}