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. javascript - swiper.js嵌套了swiper 初始设置不能向下一个滑动 结束后重新初始2. angular.js - angular-ui-bootstrap 报错无法使用?3. 为什么span的color非要内联样式才起作用?4. docker - 如何修改运行中容器的配置5. python - 如何修改twisted自带的日志输出格式?6. 老师,请问我打开browsersync出现这个问题怎么解决啊?7. 请问一下各位老鸟 我一直在学习独孤九贱 现在是在tp5 今天发现 这个系列视频没有实战8. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?9. html5 - H5做的手机分享页微信更新后,分享出去不再默认显示第一个图 作为缩略图10. 高并发写入和更新mysql

网公网安备