java - vue-resourse的post请求前端向后端传值 后端接收null
问题描述
let adrObj = { ’consignee’: this.contact, ’address’: this.detailAdress, ’province’: this.addArr[0], ’city’: this.addArr[1], ’area’: this.addArr[2], ’isDefault’: this.isDefult === true ? ’1’ : ’0’, ’consigneePhone’: ’0’ + this.phoneNum, ’id’: id, ’customerCode’: this.CUSTOMERCODE}this.$http.post(’/api/receivingAddress/editMyAddress’, adrObj).then((res) => { console.log(’success’, res)}, (res) => { console.log(’error’, res.data)})
问题描述,通过这种方式向后端传参,后端接收到的都是null
1.控制台中也有数据,但是后端接收为null2.我知道设置emulateJSON为true的话,已表单的方式提交后端可以接收到参数,但是中文是乱码的。3.有没有解决方式,可以正常使用post提交的
问题解答
回答1:根据你的描述,你后台能够接受以x-www-form-urlencoded形式提交的数据,你的代码提交的是json数据,需要修改后台。
至于x-www-form-urlencoded提交的数据中文乱码的问题,你在headers中设置一下charset试试
Vue.http.options.headers = { ’Content-Type’: ’application/x-www-form-urlencoded; charset=UTF-8’}
如果还是不行,修改后台
相关文章:
1. PHP中的$this代表当前的类还是方法?2. docker 下面创建的IMAGE 他们的 ID 一样?这个是怎么回事????3. html5 - bootstrap修改样式的问题4. linux - python 安装 Anaconda 环境变量问题请教5. css - 关于HTML中width和height的疑问(这个提问的标题不好起)6. javascript - 在 model里定义的 引用表模型时,model为undefined。7. HTML5表单必填属性设置自定义验证消息?8. java - 接口中的成员变量怎么不是常量了?9. javascript - 清空Chrome缓存的疑问10. java - 如图,jsp页面的form中的action是怎么映射到这个位置的?为什么不写dynUser就可以映射到save?

网公网安备