MDN CORS錯誤信息集合html
Access to XMLHttpRequest at 'file:///E:/Ajax/db.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.已攔截跨源請求:同源策略禁止讀取位於 file:///E:/Ajax/db.json 的遠程資源。(緣由:CORS 請求不是 http)前端
[解釋]:node
CORS請求只能使用 HTTPS URL 方案,但請求指定的 URL 多是不一樣類型。這種狀況常常發生在 URL 指定本地文件,例如使用了 file:///
的 URL。也就是說你向一個以file:///打頭的url發起請求,這是不行的ajax
[解決]:chrome
若是僅用於前端學習ajax的話,能夠安裝一個隨啓隨用的靜態文件服務器anywhere或http-server,只要搞個服務器就行,不嫌麻煩用node、tomcat上也行。安裝方法略json
(直接打開靜態文件)跨域
(anywhere命令啓動的WEB服務)tomcat
Access to XMLHttpRequest at 'http://locally.uieee.com/categories' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.已攔截跨源請求:同源策略禁止讀取位於 http://locally.uieee.com/categories 的遠程資源。(緣由:CORS 頭缺乏 'Access-Control-Allow-Origin')。服務器
[解釋]:對 CORS 請求的響應缺乏必需的Access-Control-Allow-Origin
頭,其用於肯定在當前源內操做的資源是否能夠訪問。cors