微信小程序向服务器提交POST数据

wx.request({
    url: 'https://huyahaha.com/xxxx/xxx',
    data: {
        pid: _this.data.info.id,
        nickname: _this.data.user_nickname,
        avatar: _this.data.user_avatar,
        saytext: _this.data.inputValue,
        openid: _this.data.user_openid
    },
    /** 注意header要修改, 否则无效 */
    header: {
        'content-type': 'application/x-www-form-urlencoded'
    },
    method: 'POST',
    success: function(res) {
        if (res.data.errcode == 0) {
            wx.showToast({
                title: res.data.errmsg,
                icon: 'success',
                duration: 2000
            }) _this.setData({
                inputValue: ''
            });
            /**重新加载评论列表*/
            _this.loadComment(_this.data.info.id);
        } else {
            wx.showModal({
                title: '提示',
                content: res.data.errmsg,
                showCancel: false,
                confirmText: '确定'
            }) return;
        }

    }
})

来源: https://www.huyahaha.com/index/info?id=23

猜你喜欢

转载自blog.csdn.net/qq_38832501/article/details/82460674
今日推荐