javascript origin 'http://localhost' 仅在 codeigniter 中被 CORS 策略错误阻止,我认为这与配置页面中的路径有关

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46426608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 06:40:02  来源:igfitidea点击:

origin 'http://localhost' has been blocked by CORS policies error in codeigniter only and I think it is regarding path in config page

javascriptphphtmlcodeigniter

提问by Raru

I am getting an error like:

我收到如下错误:

origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. 

This error occurs only when the design is integrated in codeigniter.

仅当设计集成到 codeigniter 中时才会发生此错误。

采纳答案by Salim Ibrogimov

You need to add headers in Your requestedpage:

您需要在您的requested页面中添加标题:

  // headers
  header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Methods: POST");
  header("Access-Control-Allow-Headers: Origin, Methods, Content-Type");

EDIT

编辑

in codeigniter:

codeigniter

$this->output
        ->set_content_type("Access-Control-Allow-Origin: *")
        ->set_content_type("Access-Control-Allow-Methods: POST")
        ->set_content_type("Access-Control-Allow-Headers: Origin, Methods, Content-Type")