- 小程序不是在浏览器中运行,无法操作DOM元素(类似document.getElementById以及Jquery的$("#id")等操作都不能进行));
- 小程序中没有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('用户点击确定') } } })
- 微信自带的ajax-----wx.request 参考:http://blog.youkuaiyun.com/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 否 接口调用结束的回调函数(调用成功、失败都会执行)
事例:
- wx.request({
- url: 'test.php',
- data: {
- x: '' ,
- y: ''
- },
- header: {
- 'Content-Type': 'application/json'
- },
- success: function(res) {
- console.log(res.data)
- }
- })
小程序踩坑(不断更新)
最新推荐文章于 2020-12-19 09:56:26 发布
1073

被折叠的 条评论
为什么被折叠?



