Ajax本地跨域問題 Cross origin requests are only supported for HTTP

問題:打開本地html文件時,報錯以下html

Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource.
 
分析:瀏覽器爲了安全性考慮,默認對跨域訪問禁止。
 
解決:給瀏覽器傳入啓動參數(allow-file-access-from-files),容許跨域訪問。
Windows下,運行(CMD+R)或創建快捷方式:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files
 
用這個方法必須關閉谷歌瀏覽器再執行纔有效
相關文章
相關標籤/搜索