Sails JS + AngularJS error: CSRF mismatch
- 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.
Comments