简体   繁体   English

IONIC否“访问控制允许来源”

[英]IONIC No 'Access-Control-Allow-Origin'

I try lunch ionic from broser with ionic serve, when i try login in my project it have error when call HTTP GET . 我尝试使用离子服务从broser提供午餐离子,当我尝试登录我的项目时,调用HTTP GET时出错。 Error like this 像这样的错误

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.1:8100' is therefore not allowed access.

I already input HTTP ORIGIN in my api.php like this 我已经在我的api.php中输入了HTTP ORIGIN

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400');    // cache for 1 day
}

if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
        header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
        header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

    exit(0);
}

I don't know why i still have error acces control allow origin, if anyone know ho to solved this problem it really helpful. 我不知道为什么我仍然有错误访问控制允许源,如果有人知道如何解决这个问题,那真的很有帮助。 Thanks 谢谢

Try it with chrome: c:\\Program Files\\Google\\Chrome\\Application>chrome.exe --disable-web-security --user-data-dir="D:\\chrome" 尝试使用chrome:c:\\ Program Files \\ Google \\ Chrome \\ Application> chrome.exe --disable-web-security --user-data-dir =“ D:\\ chrome”

The important is the disable web security. 重要的是禁用Web安全。

Points of reference 参考点

See ionic.project for configuring the proxy server. 有关配置代理服务器,请参见ionic.project。 Notice how we set the path to /api - signifying any request to the Ionic server http://localhost:8100/api will retrieve requests to the proxyUrl at http://localhost:3000/api/endpoint . 请注意,我们如何将路径设置为/ api-表示对Ionic服务器http:// localhost:8100 / api的任何请求都将在http:// localhost:3000 / api / endpoint上检索对proxyUrl的请求。

See www/js/app.js for setting up the Api Endpoint as an AngularJS constant. 有关将Api端点设置为AngularJS常量的信息,请参见www/js/app.js Notice here the address is pointed at the Ionic server. 请注意,这里的地址指向了Ionic服务器。

See www/js/services.js for using the AngularJS constant. 有关使用AngularJS常量的信息,请参见www/js/services.js

See www/js/controllers.js for using the AngularJS service. 有关使用AngularJS服务的信息,请参见www/js/controllers.js

See gulpfile.js to see how the gulp tasks are set up to replace your URL's in your files. 请参阅gulpfile.js以了解如何设置gulpfile.js任务以替换文件中的URL。

Getting started 入门

Run the following commands, the last two may require another console/terminal window: 运行以下命令,后两个命令可能需要另一个console/terminal窗口:

npm install npm nodeserver npm ionicserver

Reference : https://github.com/ionic-team/ionic-proxy-example/blob/master/README.md 参考https : //github.com/ionic-team/ionic-proxy-example/blob/master/README.md

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

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