ajax請求頭添加參數


在請求ajax時 ,有時后台要求在請求頭里邊上參數 ,這種情況下一般都是在原生APP項目當中,因為要在登錄狀態下才,所有要傳token和登錄id,

 

 

 

var token = localStorage.getItem('token')||'';
var identity = localStorage.getItem('identity')||''; 
$.ajax({
	type: params.type || 'post',
	url: dev.APIURL + params.url || null,
	dataType:'json',
	data: params.data || null,
	headers: {
	  'token':token,
	   'identity':identity,
	   'Content-Type': 'application/x-www-form-urlencoded'
	},
	success: function (res) {
	    vue.$indicator.close()
	    if(res.code != 200 && res.msg){
		vue.$toast(res.msg);
	    }
	    resolve(res)
	},
	error: function (err) {
	   reject(err)
     }
});

  

  


免責聲明!

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



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