axios post傳參后台無法接收問題


起因是在angular項目中使用axios發送post請求,向后台傳參后台一直無法接收,網上查了有說是請求頭設置不對,需要把Content-Type:application/x-www-form-urlencoded;charset=UTF-8

改了之后發現還是不行,后來終於找到原因,axios請求中params和data,不一樣,post需要把參數放在data中,get請求放在params中才行

//POST請求
sendIndentifyCodeServer(opt){ axios.post(`${environment.path}
/IdentifyingCode/getVcode`,opt.data).then((response)=>{ if(opt.onSuccess){ opt.onSuccess(response); } }).catch(error=>{ if(opt.onFailed){ opt.onFailed(error); } }); }


//GET請求
sendIndentifyCodeServer(opt){ axios.get(`${environment.path}/IdentifyingCode/getVcode`,{params:opt.data}).then((response)=>{ if(opt.onSuccess){ opt.onSuccess(response); } }).catch(error=>{ if(opt.onFailed){ opt.onFailed(error); } }); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM