官方 wx.request 代码,Post 没成功过,使用Get 方式成功了。
wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { 'content-type': 'application/json' }, success: function(res) { console.log(res.data) } })
PoST 调用代码终于被摸索出来了,我也是醉了
onLoad: function () { var that = this; wx.request({ url: 'https://www.51sdfbavvvy.cn/Mssm/HerNeeo.ashx', data:{ 'TypeID': '0', 'ImageID': 'ZNK', 'Name': '' }, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success:function(res) { that.setData({ array: res.data.array }) }, fail:function(res){ console.log('submit fail'); }, complete:function(res){ console.log('submit complete'); } }) },
我的代码:Test.wxml
<view class="section"> <input bindinput="bindKeyInput" placeholder="输入产品编号"/> <button bindtap="bindButtonTap">搜索</button> <view class="widgets__item" wx:for-items="{{array}}" wx:for-item="item" > <view id="{{item.NO}}"class="widgets__info" bindtap="onimageClick" > <image class="widget__img" src="{{item.Name}}"></image> <view class="widgettext"> <view class="widget_text1">{{item.NO}}</view> <view class="widget_text2">{{item.PrdName}}</view> </view> </view> <view class="widget__line"></view> </view> </view>
test.js
var app = getApp() var inputContent = {}//重要代码 Page({ data: { array: [], inputContent: {} }, bindKeyInput: function(e) { this.setData({ inputValue: e.detail.value }) inputContent['id'] = e.detail.value }, //---------------------------------------------------------------------- onLoad: function () { // console.log('form发生了reset事件') //页面显示时执行这里面的方法 生命周期以后会讲 var that = this; wx.request({ url: 'http://101.112.36.77:3932/WXTS/NormalPage.aspx?action=', method: 'GET', success:function(res) { that.setData({ array: res.data.array }) } }) }, //事件处理函数 onimageClick: function(event) { wx.navigateTo({ url: '../video/video-av?name='+event.currentTarget.id }) }, //------------------------------------------------------------ bindChange: function(e) { inputContent = e.detail.value }, bindButtonTap: function(e) { console.log('form发生了reset事件',inputContent['id']) var that = this; wx.request({ url: ("http://196.7.25.10:5dd5644/WXTS/NormalPage.aspx?action="+inputContent['id']),//z重要代码 method: 'GET', success:function(res) { that.setData({ array: res.data.array }) } }) }, //------------------------------------------------------------ })