[精讚] [會員登入]
1025

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

你可能感興趣的文章

[javascript] 將角色物件放到清單中,並依序讀出每個角色的X值 參考在scratch中建立三個角色並且給定值 http://n.sfs.tw/content/index/14716 一

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

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

javascript 陣列 javascript 陣列可以放各种型別的元素 let data = [1,2,"john",tru

vue.js components 多個組件的呈現 vue.js 組件 component

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

隨機好文

臺中市雲端校務系統與Windows AD帳號整合(2) 安裝Active Directory網域服務

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

Spring Boot Maven wrappers maven, mvnw, build command

如何在docker 的nginx 做另一個container的反向代理 環境 docker 中一container 跑 nginx 對外服務80 port, http://server 另一c

利用expect script 查詢ap數量,再送到google sheet及line群組通知 利用expect script 查詢ap數量