赞
踩
版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
app.js里定义请求域名
globalData: {
userInfo: null,
url:"https://www.idaobin.com/"
}
在utils目录下新建request.js
var app = getApp();
var host = app.globalData.url;
function sendPost(url, postData, doSuccess, doFail) {
wx.request({
url: host + url,
header: {
"content-type": "application/x-www-form-urlencoded;charset=UTF-8"
},
data: postData,
method: 'POST',
success: function (res) {
//参数值为res.data,直接将返回的数据传入
doSuccess(res.data);
},
fail: function () {
doFail();
},
})
}
function sendJsonPost(url, para, op, doSuccess, doFail) {
wx.request({
url: host + url,
header: {
"content-type": "application/x-www-form-urlencoded;charset=UTF-8"
},
data: {
op: op,
para
},
method: 'POST',
success: function (res) {
//参数值为res.data,直接将返回的数据传入
doSuccess(res.data);
},
fail: function () {
doFail();
},
})
}
function sendGet(url, doSuccess, doFail) {
wx.request({
url: host + url,
header: {
"content-type": "application/x-www-form-urlencoded;charset=UTF-8"
},
method: 'GET',
success: function (res) {
doSuccess(res.data);
},
fail: function () {
doFail();
},
})
}
module.exports.sendPost = sendPost;
module.exports.sendJsonPost = sendJsonPost;
module.exports.sendGet = sendGet;
调用
myClick: function (e) {
var json = JSON.stringify(this.formData);
//call.sendJsonPost('Login.ashx', json,"login" ,this.success, this.fail);
call.sendPost('Login.ashx', this.loginData, this.success, this.fail);
},
success: function (data) {
console.log(data)
},
fail: function () {
console.log("失败")
}
注意:success和fail为回调方法
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
支付宝 ——————- 微信
恰饭广告
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。