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.控制臺中也有數(shù)據(jù),但是后端接收為null2.我知道設(shè)置emulateJSON為true的話,已表單的方式提交后端可以接收到參數(shù),但是中文是亂碼的。3.有沒有解決方式,可以正常使用post提交的
問題解答
回答1:根據(jù)你的描述,你后臺能夠接受以x-www-form-urlencoded形式提交的數(shù)據(jù),你的代碼提交的是json數(shù)據(jù),需要修改后臺。
至于x-www-form-urlencoded提交的數(shù)據(jù)中文亂碼的問題,你在headers中設(shè)置一下charset試試
Vue.http.options.headers = { ’Content-Type’: ’application/x-www-form-urlencoded; charset=UTF-8’}
如果還是不行,修改后臺
相關(guān)文章:
1. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)2. 環(huán)境搭建 - anaconda 創(chuàng)建python2.7環(huán)境中打開編譯器確是3.6版本3. extra沒有加載出來4. linux - Ubuntu下編譯Vim8(+python)無數(shù)次編譯失敗5. html5 - H5頁面喚起APP導(dǎo)航6. javascript - 彈出一個子窗口,操作之后關(guān)閉,主窗口會得到相應(yīng)的響應(yīng),例如網(wǎng)站的某些登錄界面,django后臺的管理等,這是怎么實(shí)現(xiàn)的呢?7. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時間會消失是什么情況?8. mysql replace 死鎖9. list - python 求助10. python - 數(shù)據(jù)與循環(huán)次數(shù)對應(yīng)不上
