javascript - Headers in post request with Backbone.js -


I want to insert a header in my post service with a backbone.js in a post request, I try in two ways I do:

  this.model.save ({header: {'x-token': myToken}});   

Var name = "xtoken" + "="; Var ca = document.cookie.split (';'); (Var i = 0; i & lt; ca.length; i ++) for {var c = ca [i] .trim (); If (c.indexOf (name) == 0) tokenCookie = c.sublstring (name.length, c.length); } Xhr.setRequestHeader ('X-token', tokencookie); }

call:

  this.model.save ({before.Send: this.sendToken, success: work () {alert ("success" );}, Error: function (model, response, option) {warning ("error");}});   

But this does not seem to work, it does not send the header

The sign is for the model. Save ([attributes], [options]) . To add an option, you must give an empty / zero hash of properties:

  this.model.save (null, {headers: {'X-Token': 'myToken'}});   

and a demo

or

  this.model.save (null, {beforeSend: function (xhr) {xhr. SetRequestHeader ('x-token', 'set token');}});   



Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -