Apache 设置 CORS

  1. 开启Headers模块 sudo a2enmod headers

  2. 打开网站的Apache配置文档,找到 小节,添加

    Header set Access-Control-Allow-Origin “*” Header always set
    Access-Control-Allow-Methods “POST, GET, OPTIONS, DELETE, PUT”
    Header always set Access-Control-Max-Age “1000”
    Header always set Access-Control-Allow-Headers “x-requested-with, Content-Type, origin, authorization, accept,
    client-security-token”

  3. 检测配置是否正确,apachectl -t

  4. 重启服务器, sudo service apache2 reload

  5. .htaccess添加

    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]

你可能感兴趣的:(apache,ajax异步请求)