封装jq的ajax
function getData(url,ops,func){ type = "get"; url = apiurl + url; $.ajax({ type: type, url:url , dataType: "json", data: ops, error: function (err) { //请求失败时被调用的函数 console.log("失败:" + err); }, success: function (res) { func(res) } }); } 调用 getData(getMerSupCount,{},function(res){ $(".head .num01").html(res.data.merCount); $(".head .num02").html(res.data.supCount); }) es6 promise封装方法 function Getdata(url,ops,type){ //默认get url = apiurl + url; //线上http: // url = 'http://192.168.2.101:7001/'+url;//线下 var promiseObj = new Promise(function(resolve, reject) { $.ajax({ type:type, url:url, data: ops,