axios的post請求

需求:
要獲取用戶離開當前頁面時的音樂播放時長,然後post給後臺

/* 數據序列化 */
function transformRequest(data){
    var ret = '';
    for(var it in data){
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
    }
    return ret;
}

axios.post(baseURL,transformRequest({
    api_token : self.api_token,
    member_id : self.member_id,
    course_id : self.course_id,
    second : self.play_time
}).then(function(res){
    console.log(res);
}).catch(function(error){
    console.log(error);
});
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章