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. 怎么在網(wǎng)頁中設(shè)置圖片進(jìn)行左右滑動2. node.js - mysql如何通過knex查詢今天和七天內(nèi)的匯總數(shù)據(jù)3. mysql 插入數(shù)值到特定的列一直失敗4. mysql 怎么做到update只更新一行數(shù)據(jù)?5. python - 在使用Pycharm時(shí)經(jīng)常看到如下的樣式,小括號里紅色的部分是什么意思呢?6. javascript - 新浪微博網(wǎng)頁版的字?jǐn)?shù)限制是怎么做的7. python2.7 - python 函數(shù)或者類 代碼的執(zhí)行順序8. 360瀏覽器與IE瀏覽器有何區(qū)別???9. javascript - 用jsonp抓取qq音樂總是說回調(diào)函數(shù)沒有定義10. sublime可以用其他編譯器替換嗎?
