前端请求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');
解决前端请求ThinkPHP接口跨域问题
本文详细介绍了如何解决前端在请求ThinkPHP后端接口时遇到的跨域问题,通过在ThinkPHP的Controller中添加特定的header信息,如Access-Control-Allow-Origin等,实现了前端与后端的跨域资源共享。
3769

被折叠的 条评论
为什么被折叠?



