網絡請求


  1. 1.post請求:
  2. onLoad: function() {  
  3.     that = this;  
  4.     wx.request( {  
  5.       url: "url",  
  6.       header: {  
  7.         "Content-Type""application/x-www-form-urlencoded"  
  8.       },  
  9.       method: "POST",  
  10.       data: {},  
  11.       complete: function( res ) {  
  12.        console.log(res.data)
  13.         });  
  14.         if( res == null || res.data == null ) {  
  15.           console.error( '網絡請求失敗' );  
  16.           return;  
  17.         }  
  18.       }  
  19.     })  
  20.   },  
2.GET請求
  1. onLoad: function () {
        console.log('onLoad')
        var that = this
         wx.request({
          url: 'http://json.bmbstack.com/cinemaList',
          data: {},
          method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
           header: {
          'Accept': 'application/json'  
           }, // 設置請求的 header
          success: function(res){
            that.data.items= res.data
          },
          fail: function() {
            // fail
          },
          complete: function() {
            // complete
          }
        })
      }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章