I am trying to use VueJS to make a POST request. But, I cannot get past a TokenMismatchException. I have this meta tag in the main Blade template:
<meta name="token" id="token" content="{!! csrf_token() !!}">
And this at the top of my VueJS file:
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
Here is the line in my VueJS method that invokes the POST:
this.$http.post('ads/create/store', this.content);
I have tried for way too long to get the token accepted. Can anyone out there help?
You should use the 'content' attribute in the meta tag and JS
getAttribute
call:html:
js:
Here is how I set mine up, hope it helps
Possibly easier to remember for the future, you can use
If you are using the blade templating engine.
If you are in a vue instance:
Just add
before the
$http
call