top of page

Sails JS + AngularJS error: CSRF mismatch

  • Writer: Qasim Zee
    Qasim Zee
  • Feb 27, 2015
  • 1 min read

I was trying to build signup functionality with AngularJS frontend and sailsjs backend rest API. I created a simple angular post request but it was giving me following error in the browser:

CSRF mismatch

so I added the following lines to the top of post request:

$http.defaults.headers.post['X-CSRF-Token']=document.getElementsByName('_csrf')[0].value;

1

$

http

.

defaults

.

headers

.

post

[

'X-CSRF-Token'

]

=

document

.

getElementsByName

(

'_csrf'

)

[

0

]

.

value

;

Now it’s working like a charm. Please feel free to comment if you like this solution or have a better solution.

Recent Posts

See All
Joined Reddit as Software Engineer

O yeah, I joined Reddit. Based on all the offers I had at that time Reddit seemed to be the right sized company. I am currently working...

 
 
 

Comments


bottom of page