允许Google Chrome使用XMLHttpRequest从本地文件加载URL [英] Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

查看:247
本文介绍了允许Google Chrome使用XMLHttpRequest从本地文件加载URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从本地文件使用XMLHttpRequest执行HTTP请求时,由于 Access-Control-Allow-Origin 违规,它基本上失败。



但是,我自己使用本地网页,因此我想知道是否有任何方法可以让Google Chrome允许这些请求,这些请求是从本地文件到Internet上的URL 。



例如, $ .get('http://www.google.com/')失败时在本地文件中执行,但我自己编写了页面,我自己使用它,所以如果我可以禁止它并加载URL,这将非常有用。



那么,我该如何让谷歌浏览器使用本地文件中的XMLHttpRequest加载URL呢?

c $ c> - disable-web-security



在Windows上:

  chrome.exe --disable-web-security 

开Mac:

  open / Applications / Googl e \ Chrome.app/ --args --disable-web-security 

这将允许跨域请求。

我不知道这是否也适用于本地文件,但请告诉我们!



完全符合你的期望,它禁用网络安全,所以要小心。


When trying to do a HTTP request using XMLHttpRequest from a local file, it basically fails due to Access-Control-Allow-Origin violation.

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.

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.

So, how can I allow Google Chrome to load URLs using XMLHttpRequest from local files?

解决方案

startup chrome with --disable-web-security

On Windows:

chrome.exe --disable-web-security

On 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆