小程序踩坑(不断更新)

  1. 小程序不是在浏览器中运行,无法操作DOM元素(类似document.getElementById以及Jquery的$("#id")等操作都不能进行));
  2. 小程序中没有alert事件 ,存在封装好的两种消息弹窗—— 参考http://www.jb51.net/article/98187.htm;
    1,toast弹窗:
            书写方式:

    wx.showToast({
     title:'成功',
     icon:'success',
     duration: 2000
    })
     
         
    参数说明:

    2.显示模态弹窗:

    wx.showModal({
     title:'提示',
     content:'这是一个模态弹窗',
     success:function(res) {
      if(res.confirm) {
       console.log('用户点击确定')
      }
     }
    })
    参数说明:

  3. 微信自带的ajax-----wx.request 参考:http://blog.csdn.net/zgmu/article/details/53389979 ;

    参数说明:    
    参数名 类型 必填 说明
    url String 开发者服务器接口地址(有坑,如果请求的url没有在小程序官网上登记过的话会报错地址不合法)
    data Object、String 请求的参数
    header Object 设置请求的 header , header 中不能设置 Referer
    method String 默认为 GET,有效值:OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    success Function 收到开发者服务成功返回的回调函数,res = {data: '开发者服务器返回的内容'}
    fail Function 接口调用失败的回调函数
    complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

    事例:

    1. wx.request({  
    2.   url: 'test.php',  
    3.   data: {  
    4.      x: '' ,  
    5.      y: ''  
    6.   },  
    7.   header: {  
    8.       'Content-Type''application/json'  
    9.   },  
    10.   success: function(res) {  
    11.     console.log(res.data)  
    12.   }  
    13. })   

你可能感兴趣的:(小程序)