java - vue-resourse的post請(qǐng)求前端向后端傳值 后端接收null
問(wèn)題描述
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)})
問(wèn)題描述,通過(guò)這種方式向后端傳參,后端接收到的都是null
1.控制臺(tái)中也有數(shù)據(jù),但是后端接收為null2.我知道設(shè)置emulateJSON為true的話,已表單的方式提交后端可以接收到參數(shù),但是中文是亂碼的。3.有沒(méi)有解決方式,可以正常使用post提交的
問(wèn)題解答
回答1:根據(jù)你的描述,你后臺(tái)能夠接受以x-www-form-urlencoded形式提交的數(shù)據(jù),你的代碼提交的是json數(shù)據(jù),需要修改后臺(tái)。
至于x-www-form-urlencoded提交的數(shù)據(jù)中文亂碼的問(wèn)題,你在headers中設(shè)置一下charset試試
Vue.http.options.headers = { ’Content-Type’: ’application/x-www-form-urlencoded; charset=UTF-8’}
如果還是不行,修改后臺(tái)
相關(guān)文章:
1. mysql - 表名稱前綴到底有啥用?2. 致命錯(cuò)誤: Class ’appfacadeTest’ not found3. 老師們php,插入數(shù)據(jù)庫(kù)mysql,都是空的,要怎么解決4. 求大神支招,php怎么操作在一個(gè)html文件的<head>標(biāo)記內(nèi)添加內(nèi)容?5. php點(diǎn)贊一天一次怎么實(shí)現(xiàn)6. 怎么php怎么通過(guò)數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。7. PHP類屬性聲明?8. sql語(yǔ)句 - 如何在mysql中批量添加用戶?9. phpstady在win10上運(yùn)行10. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)
