请问怎么把data里的数据传到后台呀?一直报错。。。。
发布于 5 年前 作者 guiyingwei 9588 次浏览 来自 问答

var app = getApp();

Page({

  /**

   * 页面的初始数据

   */

  data: {

    src: “”,

    imageList: [],

    countIndex: 3,//最多上传图片的数量

    count: [1, 2, 3, 4, 5, 6, 7, 8, 9],

    tip:’’,

    user: ‘’,

    p: ‘’,

    title: ‘’,

    content: ‘’,

 

  },

  /**

   * 生命周期函数–监听页面加载

   */

  onLoad: function (options) {

    //接口调用示例

    var that = this

    //获取请求地址的url

    var res_url = app.globalData.res_url;

 

    //发起请求

    wx.request({

      //接口地址

 

      url: res_url + ‘index.php?g=admin&m=wxxcx&a=release’,

      method: ‘POST’,

      //请求数据

      data: {

        id: ‘1’,

        name: ‘ceshi’,

 

      },

      header: {

        “Content-Type”: “application/x-www-form-urlencoded”

      },

      //成功后回调

      success: function (res) {

        console.log(res.data)

        that.setData({

          result: res.data

        })

      }

    })

  },

  navbarTap: function (e) {

    this.setData({

      currentTab: e.currentTarget.dataset.idx

    })

  }

 

})

这是js里的数据;我想把data里的

user: '',

    p: '',

    title: '',

    content: '',这几个数据传到后台。。。。请问代码怎么写呢????

6 回复

嗯嗯,谢谢

…谁让你把function 也复制了,直接wx.request

那个,数据没有出来的说??是我那些错了????

好的,谢谢,!# ……#!   (#@-@#)

只要一加上 wx.request({})就报错。。(…@#@…)  我觉得我完不成老板交代的任务了。。。。。

function queryOrderById(that, id) {
    wx.request({
        url: app.globalData.server + “/shop/order/querybyid.action”,
        data: {
            title: that.data.title,
            content: that.data.content,
        },
        success: (res) => {
            console.log(res.data)
        }
    })
}

回到顶部