胖鸭 2012-04-13 14:50
浏览 442
已采纳

原产地不允许访问控制允许原产地

I'm making an Ajax.request to a remote PHP server in a Sencha Touch 2 application (wrapped in PhoneGap).

The response from the server is the following:

XMLHttpRequest cannot load http://nqatalog.negroesquisso.pt/login.php. Origin http://localhost:8888 is not allowed by Access-Control-Allow-Origin.

How can I fix this problem?

转载于:https://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin

  • 写回答

19条回答 默认 最新

  • hurriedly% 2012-04-13 14:54
    关注

    I wrote an article on this issue a while back, Cross Domain AJAX.

    The easiest way to handle this if you have control of the responding server is to add a response header for:

    Access-Control-Allow-Origin: *
    

    This will allow cross-domain Ajax. In PHP, you'll want to modify the response like so:

    <?php header('Access-Control-Allow-Origin: *'); ?>
    

    You can just put the Header set Access-Control-Allow-Origin * setting in the Apache configuration or htaccess file. It just work like a charm.

    From the comments, this is an important note: the wildcard is going to allow any domain to send requests to your host. I recommend replacing the asterisk with a specific domain that you will be running scripts on.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(18条)

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入