小程序文档整理之-- ajax请求

来源:互联网 发布:java抓取html指定内容 编辑:程序博客网 时间:2024/05/18 01:37
wx.request({  url: 'test.php', //(必须)接口地址,不能有端口  data: { //传入参数     x: '' ,     y: ''  },  header: {//设置请求的 header,把传入的参数转化成string      'content-type': 'application/json'//(默认)转化成JSON      'content-type': 'application/x-www-form-urlencoded'//转化成 query string   },  method: GET,//请求方式 OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT(需大写)  dataType:'json'//如果设为json,将返回的数据转化为JSON  success: function(res) {//接口调用成功的回调函数    res.data;//返回的数据    res.header;//返回的 HTTP Response Header    res.statusCode;//返回的 HTTP 状态码  },  fail: function(res){//接口调用失败的回调函数  },  complete: function(res){//接口调用结束的回调函数(成功、失败都会执行)  },})requestTask.abort() // 取消请求任务
原创粉丝点击