小程序全局ajax


util = {
request:function(appUrl,appData,called,type){
wx.showLoading({
title: '加载中...',
})
if(!type){
type = "POST";
}
wx.request({
url: appUrl,
data:appData,
header: {
'content-type': 'application/json'
},
method: type,
dataType: "json",
success: callback, //成功回调
fail: function (res) { },
complete: function (res) {
},
})
}
}

// 全局请求
request: function (appUrl, appData, callback, type) {
wx.showLoading({
title: '加载中...',
})
if (!type) {
type = "POST";
}
wx.request({
url: appUrl,
data: appData,
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: type,
dataType: "json",
success: callback, //成功回调
fail: function (res) { },
complete: function (res) {
},
})
},
原文地址:https://www.cnblogs.com/weiwentaweb/p/8590174.html