jQuery: add custom request headers


jQuery: add custom request headers

Method 1:

use option headers

$.ajax({
	url: '/v1/statistics?type=payments',
	 
	headers: {
        'Authorization': "Bearer " + access         
    },
	dataType: 'JSON',
	success: function(data){
	 
	}, 
	error: function(){
		 
	}
})

use option beforeSend

$.ajax({
	url: '/v1/statistics?type=payments',
	beforeSend: function(request) {
		request.setRequestHeader("Authorization", "Bearer " + access);
    }, 
	dataType: 'JSON',
	success: function(data){
	 
	}, 
	error: function(){
		 
	}
})

Leave a Reply