使用Laravel 5.1和VueJS的TokenMismatchException [英] TokenMismatchException using Laravel 5.1 and VueJS

查看:64
本文介绍了使用Laravel 5.1和VueJS的TokenMismatchException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VueJS发出POST请求.但是,我无法摆脱TokenMismatchException. 我在主Blade模板中有此meta标签:

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() !!}">

这是我的VueJS文件的顶部:

And this at the top of my VueJS file:

Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');

这是我的VueJS方法中调用POST的行:

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?

推荐答案

这是我的设置方法,希望对您有所帮助

Here is how I set mine up, hope it helps

<meta name="_token" content="{{ csrf_token() }}">

//get the token from the meta tag
$('meta[name="_token"]').attr('content');

这篇关于使用Laravel 5.1和VueJS的TokenMismatchException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆