I want to put a headers in a post request to my REST service with Backbone.js , I try two ways :
this.model.save( { headers: {'X-Token' : myToken } } );
and with a setResquestHeader :
the function :
sendToken: function (xhr) {
var tokenCookie;
var name = "xtoken" + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++)
{
var c = ca[i].trim();
if (c.indexOf(name)==0) tokenCookie = c.substring(name.length,c.length);
}
xhr.setRequestHeader('X-Token', tokenCookie);
}
the call :
this.model.save({
beforeSend: this.sendToken,
success: function() {
alert("success");
},
error: function(model,response,options) {
alert("error");
}
});
But it doesn't seem to work , it doesn't send the header