Con jQuery possiamo impostare header HTTP aggiuntivi per le richieste AJAX.
La soluzione è la seguente e consiste nell'impostare gli header aggiuntivi come coppie di chiavi/valori all'interno dell'oggetto letterale headers:
(function( $ ) {
$(function() {
var settings = {
url: "/test",
method: "GET",
data: { s: "test" },
dataType: "json",
headers: {
"my-header": "test"
},
success: function( response ) { }
};
$.ajax( settings );
});
})( jQuery );