1

我需要在 ubuntu 上配置 apache 来接受 POST 跨域。

我试过这样http://enable-cors.org/server_apache.html

  1. 安装 mod_header
  2. 添加 header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Access-Control-Max-Age: 1000'); header('Access-Control-Allow-Headers: Content-Type');

但这不起作用。

请求标头:

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, cache-control, origin, x-requested-with, x-file-name, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:xxx.amazonaws.com
Origin:local.com
Referer:local.com/test/test.php
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31

响应标头:

Access-Control-Allow-Methods:POST, GET, OPTIONS
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:27
Content-Type:text/html Date:Fri, 10 May 2013 10:30:10 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.22 (Ubuntu) Vary:Accept-Encoding X-Powered-By:PHP/5.3.10-1ubuntu3.6

任何人都可以帮助我吗?太感谢了

4

1 回答 1

1

继续在 jQuery 论坛上的某个线程中提供给某人的答案,您可能需要提供“Access-Control-Allow-Headers”标头,以便允许发送某些标头。

header("Access-Control-Allow-Headers: X-Requested-With, X-File-Name")

参考:http: //forum.jquery.com/topic/jquery-1-5-latest-chrome-post-ajax-request-xmlhttprequest-cannot-load-url-request-header-field-x-requested-with- is-not-allowed-by-access-control-allow-headers

于 2013-05-10T10:34:51.160 回答