Closed chytreg closed 11 years ago
It wouldn't work if you don't have jQuery - built in angular.element
will not find selector meta[name=csrf-token]
. Proper solution:
meta = document.querySelector('meta[name=csrf-token]')
if meta && meta.hasAttribute('content')
app.config ['$httpProvider', (provider) ->
provider.defaults.headers.common['X-CSRF-Token'] = meta.getAttribute('content')
]
querySelector is not supported on IE7
If you need to support ancient tools, use jQuery, or something similar.
You may use jQuery on ancient tools, but snippet you provided won't work.
Something like this will:
for meta in document.getElementsByTagName('meta')
if meta.name.toLowerCase() == "csrf-token" && meta.content
app.config ['$httpProvider', (provider) ->
provider.defaults.headers.common['X-CSRF-Token'] = meta.content
]
You may use jQuery on ancient tools, but snippet you provided won't work.
You didn't understood me. With jQuery you can use angular.element
from the PR.
I think we need only one snippet
Sure, :+1: for your solution @sheerun :)
@chytreg Could you update PR and merge?
done :)
+1