更多:http://www.webyang.net/Html/web/article_135.html
最新的W3C标准里是这么实现HTTP跨域请求的,
Cross-Origin Resource Sharing具体操作方法, 可以通过不同入口来控制:
一、php代码控制:<ol> <li value="1"> <span></span><span>php</span> </li> <li> <span>header</span><span>(</span><span>"Access-Control-Allow-Origin: *"</span><span>);</span> </li> <li><span>?></span></li> </ol>
<ol><li value="1"><span><meta> <span></span><span>http-equiv</span><span>=</span><span>"Access-Control-Allow-Origin"</span><span></span><span>content</span><span>=</span><span>"*"</span><span>></span></span></li></ol>
<ol> <li value="1"> <span>location </span><span>/</span><span></span><span>{</span> </li> <li> <span> add_header </span><span>Access</span><span>-</span><span>Control</span><span>-</span><span>Allow</span><span>-</span><span>Origin</span><span></span><span>*;</span> </li> <li><span>}</span></li> </ol>
<ol> <li value="1"><span>#授权从other.subdomain.com的请求</span></li> <li> <span>add_header </span><span>'Access-Control-Allow-Origin'</span><span></span><span>'http://other.subdomain.com'</span><span>;</span> </li> <li><span>#当该标志为真时,响应于该请求是否可以被暴露</span></li> <li> <span>add_header </span><span>'Access-Control-Allow-Credentials'</span><span></span><span>'true'</span><span>;</span> </li> <li><span>#指定请求的方法,可以是GET,POST等</span></li> <li> <span>add_header </span><span>'Access-Control-Allow-Methods'</span><span></span><span>'GET'</span><span>;</span> </li> </ol>
不过我自己测试了一下,是不需要的。另如果要指定特定的域名,只要修改*即可,一般都是开放站点的二级域名。
以上就介绍了Nginx 实现AJAX跨域请求,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。