在我們訪問文件的時候,會出現
No 'Access-Control-Allow-Origin' header is present on the requested resource.之類的提示,遇到這種問題最簡單的方式就是在服務器進行配置,當然客戶端的方式就是jsonp,但是麻煩,還是下面的解決方式比較簡單
vi /etc/nginx/nginx.conf
加入如下代碼
http { ###start#### add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; ###end ### }
:wq 保存
service nginx restart 重啟nginx即可。