【微信小程序】封装http请求
来源:互联网 发布:cn域名ns记录是什么 编辑:程序博客网 时间:2024/06/10 01:12
原文地址:http://www.cnblogs.com/happen-/p/6278327.html
在utils文件中创建js文件:
//request.jsvar root = "http://uat.gfcarnival.com:8088/ACClient/"; //以实际地址为准var app = getApp(); //获得app.js的属性方法var sendRrquest = function (url, method, data, header) { data = data || {}; header = header || {}; data = app.extend(data, app.globalData.data); //data和全局data对象相加 var promise = new Promise(function (resolve, reject) { wx.request({ url: root + url, data: data, method: method, header: app.globalData.header, success: resolve, fail: reject }) //微信请求API console.log("请求参数:"); console.log(data); console.log("请求方法:"); console.log(method); console.log("请求头:"); console.log(header); }); return promise;}; module.exports.sendRrquest = sendRrquest
在其他js文件中引用:
var request = require('../../utils/request.js')var url = "jfbs/jfbs1001/getBanners.do?"; //接口,以实际为准var app = getApp();onLoad: function() { var that = this; request.sendRrquest(url, 'GET', { data:data }, ) .then(function (res) { console.log("返回数据:"); console.log(res); }, function (error) { console.log("返回失败:"); console.log(error); });
阅读全文
0 0
- 【微信小程序】封装http请求
- 微信小程序初体验--封装http请求
- 微信小程序-封装http请求(ajax)
- 微信小程序 http请求封装详解及实例代码
- Android封装Http请求
- Block封装http请求
- http请求封装
- 简单封装 HTTP 请求
- go http 请求封装
- http请求方法封装
- http封装ajax请求
- 微信小程序开发:http请求
- 微信小程序入门 请求的封装
- 【微信小程序】网络请求接口封装实例
- 微信小程序之网络请求简单封装
- 微信小程序之封装请求函数
- Java HTTP请求类封装
- Android Http网络请求封装
- cocos2dx 通用性能优化方案
- python各种安装包的下载地址
- GSON@JSON
- window.location.href用法
- iOS远程推送点击消息跳转到指定页面
- 【微信小程序】封装http请求
- 对称的二叉树
- Rails代码品质辅助工具
- Centos7:5分钟安装python3.5 并存python2.7,兼容yum及Gnome
- Makefile十四之隐含规则
- Quartz动态调控任务管理
- DNS域名解析过程
- 文件的写入操作
- Android中删除EditText中内容时报SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length