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 - mongodb怎么设置用户的账户不重复?2. 请问各位java自带类的一些问题3. python 字符串匹配问题4. redis sentinel怎么跑守护进程以及日志记录位置的?5. css - transition 的使用?6. 请问PHPstudy中的数据库如何创建索引7. Python异常退出时保存进度?8. 前端 - 这段代码一直生效不了,查半天因为 top: 0px; 分号后一个隐藏的东西,也不是占位符...删了就可以生效,这是什么情况。。9. javascript - sublime快键键问题10. html - angular项目中如何让外链网页在本项目中展示?

网公网安备