允许 Google Chrome 使用 XMLHttpRequest 从本地文件加载 URL [英] Allow Google Chrome to use XMLHttpRequest to load a URL from a local file
问题描述
当尝试使用来自本地文件的 XMLHttpRequest 执行 HTTP 请求时,由于Access-Control-Allow-Origin
违规,它基本上失败了.
When trying to do a HTTP request using XMLHttpRequest from a local file, it basically fails due to Access-Control-Allow-Origin
violation.
但是,我自己使用的是本地网页,所以我想知道是否有任何方法可以让 Google Chrome 允许这些从本地文件到 Internet 上的 URL 的请求.
However, I'm using the local web page myself, so I was wondering if there is any way to make Google Chrome allow these requests, which are from a local file to a URL on the Internet.
例如,$.get('http://www.google.com/')
在本地文件中执行时失败,但我自己编写了页面脚本并且我正在使用它自己,所以如果我能抑制它并加载 URL 将非常有用.
E.g., $.get('http://www.google.com/')
fails when executing in a local file, but I've scripted the page myself and I'm using it myself, so it would be extremely useful if I could suppress it and load the URL.
那么,如何允许 Google Chrome 使用 XMLHttpRequest 从本地文件加载 URL?
So, how can I allow Google Chrome to load URLs using XMLHttpRequest from local files?
推荐答案
使用 --disable-web-security
在 Windows 上:
On Windows:
chrome.exe --disable-web-security
在 Mac 上:
open /Applications/Google Chrome.app/ --args --disable-web-security
这将允许跨域请求.
我不知道这是否也适用于本地文件,但请告诉我们!
This will allow for cross-domain requests.
I'm not aware of if this also works for local files, but let us know !
请注意,这完全符合您的预期,它禁用网络安全,所以要小心.
And mention, this does exactly what you expect, it disables the web security, so be careful with it.
这篇关于允许 Google Chrome 使用 XMLHttpRequest 从本地文件加载 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!