且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

原产地不是由访问控制 - 允许 - 原产地允许

更新时间:2022-06-22 01:10:51

我写了关于这个问题的文章而回,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.