開發angular.js時,因為引用外部文件導致Chrome的Console報錯。訊息:Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https。簡單地說,就是這種操作文件方式,只支援在使用http, , data, chrome-extension, https協議時。 為了解決這個問題,可以將你的文件放到一個網頁伺服器上。Python剛好有一個自帶的網頁伺服器,下面是具體操作的方法: 下載安裝Python 3.6.3到Windows10作業系統中。 WIN+R輸入cmd開啟console。 切換到網頁所在路徑,舉例:網頁位於Foo\index.html,輸入 cd Foo<ENTER> 。 輸入 python -m http.server 啟動網頁伺服器。 開啟Chrome在路徑列中輸入 http://127.0.0.1:8000/index.html ,就能看到你的首頁。 捷徑 可以在桌面建立捷徑,就不必每次都打指令。具體操作的方法如下: 在網頁所在路徑下,編輯一檔案名為start_web_server.bat。 檔案內容為 @echo off python -m http.server 在檔案上按右鍵開啟選單 Send to| Desktop (Create shortcut) 參考 https://stackoverflow.com/questions/27742070/angularjs-error-cross-origin-requests-are-only-supported-for-protocol-schemes
留言
張貼留言