学无先后,达者为师

网站首页 PHP其他 正文

前端请求thinkPHP接口报错。Respnse to preflight request doesn't pass access control check

作者:phoebe_huang 更新时间: 2022-03-15 PHP其他

前端请求thinkPHP接口报错。

报错信息如下所示:

 

解决: 在ThinkPHP\Library\Think\Controller.class.php中加入

  

                header('Access-Control-Allow-Origin: http://localhost:8080');     // 前端访问地址

                header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

                header('Access-Control-Allow-Methods: GET, POST, PUT');

                header('Access-Control-Allow-Credentials: true');


原文链接:https://blog.csdn.net/PigBiBiX/article/details/84715442

栏目分类
最近更新