本文介紹了跨域請求本地文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要在瀏覽器中打開一個本地 html 文件.javascript 工作正常,但 ajax 停止工作,并且 XMLHttpRequest 給出了跨源錯誤.有沒有辦法從本地目錄運行 ajax.我有必要只從本地文件運行它.
I need to open a local html file in the browser. The javascript works fine but ajax stops working and XMLHttpRequest gives a cross origin error. Is there a way to run ajax from local directory. It is necessary for me that it is run from local file only.
謝謝
推薦答案
對于任何想知道的人,我必須在應用程序中運行一個服務器來提供 js 文件.似乎不運行服務器就不可能做到這一點.如果有人知道另一種方法,請告訴.
For anyone who wants to know, I had to run a server in the app to serve the js files. Seems like it's not possible to do it without running a server. If anyone knows of another way, do tell.
這篇關于跨域請求本地文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!