跨域请求本地文件

我需要在浏览器中打开一个本地 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.

相关文章