doukou4066 2015-11-12 07:06
浏览 96
已采纳

HMVC Codeigniter中没有“Access-Control-Allow-Origin”错误

When Page loads in my console it shows this error

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.

and when i call ajax function. it show this error

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.

Which ajax functions are in home controller. But i'm in another controller. may be I think it was problem. how can i solve this ?

  • 写回答

2条回答 默认 最新

  • duanping1632 2015-11-12 07:18
    关注

    For Cross-Origin Resource in Codeignitor you have to include this line in controller right after start of <?php tag

    header('Access-Control-Allow-Origin: *');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?