javascript - HMVC Codeigniter 中没有 'Access-Control-Allow-Origin' 错误

标签 javascript php ajax codeigniter codeigniter-2

当页面在我的控制台中加载时,它会显示此错误

Font from origin 'http://example.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.example.com' is therefore not allowed access.

当我调用 ajax 函数时。它显示此错误

XMLHttpRequest cannot load http://example.com/index.php/home/getCity?city=d. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.example.com' is therefore not allowed access.

家庭 Controller 中有哪些ajax功能。但我在另一个 Controller 中。可能是我认为这是问题。我该如何解决这个问题?

最佳答案

对于 Codeignitor 中的跨源资源,您必须在 <?php 启动后立即在 Controller 中包含此行标签

header('Access-Control-Allow-Origin: *');

关于javascript - HMVC Codeigniter 中没有 'Access-Control-Allow-Origin' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665963/

相关文章:

php - 我如何在php中获取上传文件的内容?

php - 仅使用 Wordpress 中的库在 PHP 中读取 JSON

Ajax 请求不是异步的

javascript - Ajax 循环调用

javascript - jQuery 在 while 循环数据中获取来自 AJAX 的属性值

javascript - jsTree, hover_node, 事件

javascript - 使用 innerHTML 和/或替换修改 HTML 文本

javascript - 等待结果后再继续

javascript - 这段 ES6 代码做了什么?

PHP 多对多集合 ID