angularjs - angular, django and csrf -


from http://docs.angularjs.org/api/ng.$http , says should set default headers include token, following it.

my code goes this

var myapp = angular.module('myapp', ['ngcookies', 'ui.bootstrap']).     config(['$routeprovider', function($routeprovider, $httpprovider, $cookies){         $routeprovider.             when('/', {                 templateurl: '/partials/home.html',                 controller: homectrl             }).             when('/game/:gameid/shortlist/create',{                 templateurl: '/partials/create-shortlist.html',                 controller: createshortlistctrl             }).             otherwise({redirectto: '/'});     }]);  myapp.run(function($rootscope, $http, $cookies, $httpprovider){     $http.get('/api/get-current-user').success(function(data){         $rootscope.current_user = data;         $rootscope.current_team = $rootscope.current_user.team;     });     $http.get('/api/get-current-season').success(function(data){         $rootscope.current_season = data;     });     $rootscope.csrf_token = $cookies.csrftoken;     console.log($httpprovider.defaults.headers.common);     //$httpprovider.defaults.headers.post['x-csrftoken'] = $cookies.csrftoken; }); 

as can see, have applied multiple approaches unable set header csrf token. 2 errors have encountered are

uncaught error: unknown provider: $httpproviderprovider <- $httpprovider

what doing wrong?

if use angularjs 1.1.3 or newer can use xsrfheadername , xsrfcookiename:

var myapp = angular.module('myapp', ['ngcookies', 'ui.bootstrap']).   config(['$routeprovider', function($routeprovider, $httpprovider, $cookies){     $httpprovider.defaults.xsrfheadername = 'x-csrftoken';     $httpprovider.defaults.xsrfcookiename = 'csrftoken';     ... 

see $location in 1.1.3 documentation.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -