Using Angular.js $http.post with Codeigniter WITH CSRF enabled Using Angular.js $http.post with Codeigniter WITH CSRF enabled codeigniter codeigniter

Using Angular.js $http.post with Codeigniter WITH CSRF enabled


Here is a solution:

var postData = $.param({csrf_token: $("input:hidden[name='csrf_token']").val()});$http.post('myCIcontroller', postData, {headers : {'Content-Type': 'application/x-www-form-urlencoded'}}).success(function(data){            console.log(data);});

More info here:How can I post data as form data instead of a request payload?


Try:

var postData = { csrf_token: $("input:hidden[name='csrf_token]").val() };

This basically does the same as your jquery ajax call. You might also want to get rid of the headers in $http.post().