简体   繁体   English

如何在角度中为交叉原点设置xsrf标记

[英]How to set xsrf token in angular for cross origin

i am using angular js in front end and laravel in back end. 我在前端使用角js,在后端使用laravel。 I want to set xsrf token for access cross origin 我想为访问跨源设置xsrf令牌

but I'm getting this --> Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. 但我得到了这个 - >只有协议方案才支持交叉源请求:http,数据,chrome,chrome-extension,https,chrome-extension-resource。

i have angular js module as follow 我有角度js模块如下

 angular.module('myapp', ['ngRoute']).run(function($http,CSRF_TOKEN){ $http.defaults.headers.common['csrf_token'] = CSRF_TOKEN; }); 

and my service is as follow 我的服务如下

 angular.module('myapp').factory('communitiesService', function($http) { return { get : function() { return $http.get('http://localhost:8000/api/v1/communities/searchcommunities'); } } }); 
I have this in view file 我在视图文件中有这个

 <script> angular.module("myApp").constant("CSRF_TOKEN", '<?php echo csrf_token(); ?>'); </script> 

can anyone provide me the complete example and explain. 任何人都可以提供完整的例子和解释。

thank you 谢谢

在App \\ Http \\ Middleware \\ VerifyCsrf.php中添加项目uri

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM