原产地不是由访问控制 - 允许 - 原产地允许 [英] Origin is not allowed by Access-Control-Allow-Origin

查看:304
本文介绍了原产地不是由访问控制 - 允许 - 原产地允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的的Ajax.Request 来远程PHP服务器=htt​​ps://en.wikipedia.org/wiki/Sencha_Touch >煎茶触摸 2应用程序(包裹在 PhoneGap的)。

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

从服务器的响应如下:

XMLHtt prequest无法加载 http://nqatalog.negroesquisso.pt/login.php 。原产地的http://本地主机:8888 不受访问控制 - 允许 - 原产地允许

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?

推荐答案

我写了关于这个问题的文章而回,<一个href="http://www.cy$p$pssnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/">Cross域AJAX 。

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: *

这将允许跨域阿贾克斯。在PHP中,你要修改,像这样的反应:

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

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

您只需把标题设置访问控制 - 允许 - 产地* 中的阿帕奇配置或htaccess文件。这只是工作就像一个魅力。

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.

这篇关于原产地不是由访问控制 - 允许 - 原产地允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆