微信小程序用户注册界面

‘Content-Type’: 'application/json’用在get请求中没问题.
POST请求就不好使了.需要改成: “Content-Type”: “application/x-www-form-urlencoded”

表单内容用框起来
form-type='confirm’设置点击事件

js文件内容:
举例:

data:{
   username:’’
}
  user_nameInput: function(e) {
    this.setData({
      user_name: e.detail.value
    })
  },

/表单提交/

  formSubmit: function(options) {
    console.log(options)
    wx.request({
      url: 'http://www.baidu.com', // 仅为示例,并非真实的接口地址
      data: options.detail.value,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      method: "POST",

      success: (res) => {
        console.log(rest.data)
        if (res.error) {
          wx.showToast({
            title: 'res.data.msg',
            icon: 'none',
            duration: 2000
          })
        } else {
          wx.showToast({
            title: '添加成功!',
            icon: 'succeess',
            duration: 2000
          })
        }
      }
    })
  },

注意:
1、关于校验合法域名的问题(出现request: fail invalid url 错误):
设置->项目设置->勾选不校验合法域名。
2、value值要和后端设置的一样,不然注册不了,注意区分中英文。

发布了32 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/rating_/article/details/89301612