angularjs + PHP应用程序中的CORS错误 [英] CORS error in angularjs + PHP application

查看:65
本文介绍了angularjs + PHP应用程序中的CORS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究AngularJS和PHP应用程序。当我尝试运行index.html页面时,抛出此错误

I'm working on AngularJS and PHP application. When I try to run the index.html page, its throwing this error,


MLHttpRequest无法加载http:// ... 。请求的
资源上没有
'Access-Control-Allow-Origin'标头。因此,不允许访问来源 http:// localhost
响应的HTTP状态码为500。

MLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 500.

正在使用LAMP。
我知道我需要包括头文件。但是我应该在哪里添加呢?我应该在定义数据库的config.php中包括它吗?如果不是,那么在哪里?

Working on LAMP. I know I need to include the header files. But where should I include it? Should I include it in config.php where I had definded my database? If not then where??

推荐答案

您在PHP 标头,尝试添加以下内容:

You are missing CORS settings on your PHP headers, try adding following:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
header('Access-Control-Allow-Credentials: true');

这篇关于angularjs + PHP应用程序中的CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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