Cross-origin request for local file(跨域请求本地文件)
问题描述
我需要在浏览器中打开一个本地 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.
这篇关于跨域请求本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:跨域请求本地文件


基础教程推荐
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01