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. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?2. python没入门,请教一个问题3. 小程序怎么加外链,语句怎么写!求救新手,开文档没发现4. php如何获取访问者路由器的mac地址5. java 线程监控 重启线程 观察者模式的问题的问题6. javascript - 在 vue里面用import引入js文件,结果为undefined7. 求教一个mysql建表分组索引问题8. node.js - 用nodejs 的node-xlsx模块去读取excel中的数据,可是读取出来的日期是数字,请问该如何读取日期呢?9. html5 - input type=’file’ 上传获取的fileList对象怎么存储于浏览器?10. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?
