更多:http://www.webyang.net/Html/web/article_135.html
最新的W3C標準裡是這麼實現HTTP跨域請求的,
Cross-Origin Resource Sharing<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>二、html頭控制:
<ol><li value="1"><span><meta</span><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></li></ol>三、nginx配置:
<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>在網路上看到有人會在nginx.conf加三句話:
<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教學有興趣的朋友有幫助。