[精讚] [會員登入]
1054

axios vuejs application/x-www-form-urlencoded 送資料

VUE.JS 以 application/x-www-form-urlencoded 送資料

分享此文連結 //n.sfs.tw/11468

分享連結 axios vuejs application/x-www-form-urlencoded 送資料 @igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-25 13:09:42 最後編修
2017-07-19 00:23:08 By igogo
 

結論: 只有chrome 適用 , 我還是默默的用json 傳值

 

如圖, vue.js+axios 送出json 的物件很簡單, 但是如果想送的是像form action submit的資料時要怎麼做呢

 

Vue.prototype.$http = axios;
    var config = {
        headers: {
        'content-type': 'application/x-www-form-urlencoded'
        }
   };

http request 使用axios,  content-type 改application/x-www-form-urlencoded

 

var params = new URLSearchParams();
params.append('keywords', this.keywords);

https://github.com/mzabriskie/axios/issues/362

但此法IE 不適用

最後送出

this.$http.post(url, params, config)
.then((response) => {
    // success callback
    console.log(response.data);
}, (response) => {
    // error callback
});

 

後記, 經現下的版本測試 只有chrome 認得URLSearchParams()  我總不能要求使用者使用特定browser 吧

只好默默改用application/json 傳值, server端再以object收值  或是parse json 的方式

 

END

你可能感興趣的文章

vue js 與teleport vue js 與 teleport 範例 <!DOCTYPE html> <html> <

word題目轉google測驗 word題目轉google測驗

vue.js component 在parent與child 傳值 component 在parent與child 傳值

將google試算表當作簡易資料庫,利用Google apps cript 在網頁上操作查詢 將google試算表當作簡易資料庫,利用apps cript 在網頁上操作查詢 若我有一試算表資料 縣市 status

[vue.js] 動態的props 做parent-child components 雙向綁定 vue.js props components camel-case

[vue.js] input event Form-Input-Components-using-Custom-Events

隨機好文

2018 hoc 頒獎 校慶到了,啦啦隊比賽如火如荼展開,學務主任將頒發獎狀給表現優異的班級。請完成以下程式碼,讓程式將啦啦隊表演成績由高至低依序輸出。

雲端校務系統與OPENLDAP帳號整合(2) openldap,雲端校務

ArrayList 與 HashMap 範例 public static void main(String[] args) { String titleIds = &

scratch3 計算得分排名 scratch3 得分排名

刪除資料夾內的檔案 lambda 一行文 Arrays.stream(new File("/folder/path").