我正在尝试使用axios和最后一个Laravel版本5.5提出一些请求
配置X-CSRF字段后全部
我的代码很简单:
配置X-CSRF字段后全部
我的代码很简单:
axios.post('/post-contact',{name:'Kamal Abounaim'}) .then((response)=>{ console.log(response) }).catch((error)=>{ console.log(error.response.data) })
但我得到这个错误:419(未知状态)
应该是什么问题
谢谢回答
解决方法
这是因为csrf-token发生的.只需在< head>中添加带有csrf-token的元标记.并将该标记添加到axios标头中.
// in the <head> <Meta name="csrf-token" content="{{ csrf_token() }}"> <script type="text/javascript"> // For adding the token to axios header (add this only one time). var token = document.head.querySelector('Meta[name="csrf-token"]'); window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; // send contact form data. axios.post('/post-contact',{name:'Kamal Abounaim' }).then((response)=>{ console.log(response) }).catch((error)=>{ console.log(error.response.data) }); </script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。