wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { 'Content-Type': 'application/json' }, success: function(res) { console.log(res.data) }})
function json2Form(json) { var str = []; for(var p in json){ str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p])); } return str.join("&"); }
图片:1.png
2、测试用例
2.1 get请求//GET方式let map = new Map();map.set( 'receiveId', '0010000022464' );let d = json_util.mapToJson( util.tokenAndKo( map ) );console.log( d );var url1 = api.getBaseUrl() + 'SearchTaskByReceiveId?data='+d;network_util._get( url1,d,function( res ) {console.log( res );that.setData({ taskEntrys:res.data.taskEntrys});}, function( res ) {console.log( res );});
2.2 POST请求//Post方式 let map = new Map(); map.set( 'receiveId', '0010000022464' ); let d = json_util.mapToJson( util.tokenAndKo( map ) ); console.log( d ); var url1 = api.getBaseUrl() + 'SearchTaskByReceiveId'; network_util._post( url1,d, function( res ) { console.log( res ); that.setData({ taskEntrys:res.data.taskEntrys }); }, function( res ) { console.log( res ); });图片:2.png
效果图片:3.png
以上就是小程序开发之网络请求的封装教程的详细内容,更多请关注php中文网其它相关文章!
已抢64875个
抢已抢27345个
抢已抢14756个
抢已抢7399个
抢已抢9279个
抢已抢18413个
抢