javascript - Set custom header in Backbone.js not working -
i trying set custom header in backbone.js application in save method. header isn't being set, though can set header in fetch method.
switch(method){ case 'read' : model.fetch({ headers:{ "override-authorization":'basic ' + proxyauth } }); break; case 'create' || 'update' : sendauthentication = function (xhr) { xhr.setrequestheader('override-authorization','basic ' + proxyauth); }; model.save({ beforesend:sendauthentication, headers:{ "override-authorization":'basic ' + proxyauth } }); break; case 'delete' : model.delete({ headers:{ "override-authorization":'basic ' + proxyauth } }); break; } in first case, fetch call, header gets set properly. in second case, save method, header isn't set, though i've tried both ways. thoughts?
you may want have @ model#save's doc.
model.save([attributes], [options]) you're setting attributes model instead of overriding headers.
model.save({}, { beforesend:sendauthentication, headers:{ "override-authorization":'basic ' + proxyauth } }); will trick.
Comments
Post a Comment