&quot'Cross Origin请求仅支持HTTP。”加载本地文件时出错

发布于 2025-01-22 09:04:49 字数 147 浏览 0 评论 0 原文

我正在尝试将3D模型加载到本地存储在我的计算机上,并使用 jsonloader 将3D模型与整个网站相同的目录中。

我得到“跨越来源的请求仅支持HTTP。” 错误,但我不知道是什么原因导致了它,也不知道如何修复它。

I'm trying to load a 3D model, stored locally on my computer, into Three.js with JSONLoader, and that 3D model is in the same directory as the entire website.

I'm getting the "Cross origin requests are only supported for HTTP." error, but I don't know what's causing it nor how to fix it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

花开雨落又逢春i 2025-01-29 09:04:50

我的水晶球说您正在使用 file:// c:/加载模型,因为它们不是 http ://

因此您可以在本地PC中安装Web服务器,也可以将模型上传到其他地方,然后使用 JSONP ,然后将URL更改为 http://example.com/路径/to/model

oneration在 rfc-6454

   ...they have the same
   scheme, host, and port.  (See Section 4 for full details.)

尽管您的文件源自同一主机( localhost ),但只要该方案不同( http / file> file ),它们就会得到处理。作为不同的起源。

My crystal ball says that you are loading the model using either file:// or C:/, which stays true to the error message as they are not http://

So you can either install a webserver in your local PC or upload the model somewhere else and use jsonp and change the url to http://example.com/path/to/model

Origin is defined in RFC-6454 as

   ...they have the same
   scheme, host, and port.  (See Section 4 for full details.)

So even though your file originates from the same host (localhost), but as long as the scheme is different (http / file), they are treated as different origin.

月下客 2025-01-29 09:04:50

只是要明确 - 是的,错误是说您不能直接指向浏览器 file> file://some/path/some.html

这里有一些选择,可以快速旋转本地Web服务器以便 则浏览器渲染本地文件

python

如果您安装了python,

  1. ...

    将目录更改为文件夹中的文件 some.html < /code>或使用命令 cd /path存在文件(s) /to/您的/文件夹


  2. 启动python Web服务器使用以下命令之一

    之一

    python -m simplehttpserver#python 2

    python3 -m http.server#python 3

这将启动一个Web服务器,以托管您的整个目录列表,at http:// localhost:8000

  1. 您可以使用自定义端口 python3 -m http.server 9000 提供链接: http:// localhost:9000 要指向您的浏览器

对此方法的指向任何Python安装。

vscode

如果您使用的是 Visual Studio Code 您可以安装

node.js

,如果您需要更响应的设置,并且已经使用nodejs ...

  1. install http-server 通过键入 NPM安装-G http -server

  2. 更改为工作目录,其中 some.html lives lives < /p>

  3. 通过发行 http-server -c-c-1

    启动http服务器

然后旋转一个node.js httpd,该httpd将目录中的文件服务为静态文件,可从 http:// localhost:8080

ruby

​​如果您喜欢的语言是Ruby ... Ruby gods也说这也有效:

ruby -run -e httpd . -p 8080

PHP

当然也具有解决方案。

php -S localhost:8000

Just to be explicit - Yes, the error is saying you cannot point your browser directly at file://some/path/some.html

Here are some options to quickly spin up a local web server to let your browser render local files

Python

If you have Python installed...

  1. Change directory into the folder where your file some.html or file(s) exists using the command cd /path/to/your/folder

  2. Start up a Python web server using one of below commands

    python -m SimpleHTTPServer # python 2

    python3 -m http.server # python 3

This will start a web server to host your entire directory listing at http://localhost:8000

  1. You can use a custom port python3 -m http.server 9000 giving you link: http://localhost:9000 to point your browser at

This approach is built in to any Python installation.

VSCode

If you are using Visual Studio Code you can install the Live Server extension which provides a local web server ... after installing this extension click on Go Live widget on bottom of vscode window to launch browser pointing at your code dir

Node.js

Alternatively, if you demand a more responsive setup and already use nodejs...

  1. Install http-server by typing npm install -g http-server

  2. Change into your working directory, where yoursome.html lives

  3. Start your http server by issuing http-server -c-1

This spins up a Node.js httpd which serves the files in your directory as static files accessible from http://localhost:8080

Ruby

If your preferred language is Ruby ... the Ruby Gods say this works as well:

ruby -run -e httpd . -p 8080

PHP

Of course PHP also has its solution.

php -S localhost:8000
药祭#氼 2025-01-29 09:04:50

在Chrome中,您可以使用此标志:

--allow-file-access-from-files

在此处阅读更多:如何使用chrome at” - “ hallow-file-access-from-files”模式启动HTML?

In Chrome you can use this flag:

--allow-file-access-from-files

Read more here: How to launch html using Chrome at "--allow-file-access-from-files" mode?

半﹌身腐败 2025-01-29 09:04:50

今天跑去。

我编写了一些看起来像这样的代码:

app.controller('ctrlr', function($scope, $http){
    $http.get('localhost:3000').success(function(data) {
        $scope.stuff = data;
    });
});

...但是应该看起来像这样:

app.controller('ctrlr', function($scope, $http){
    $http.get('http://localhost:3000').success(function(data) {
        $scope.stuff = data;
    });
});

唯一的区别是代码第二段中缺少 http://

只是想在其他情况下遇到类似问题的其他问题。

Ran in to this today.

I wrote some code that looked like this:

app.controller('ctrlr', function($scope, $http){
    $http.get('localhost:3000').success(function(data) {
        $scope.stuff = data;
    });
});

...but it should've looked like this:

app.controller('ctrlr', function($scope, $http){
    $http.get('http://localhost:3000').success(function(data) {
        $scope.stuff = data;
    });
});

The only difference was the lack of http:// in the second snippet of code.

Just wanted to put that out there in case there are others with a similar issue.

在你怀里撒娇 2025-01-29 09:04:50

只需将URL更改为 http:// localhost 而不是 localhost 。如果您从本地打开HTML文件,则应创建一个本地服务器来服务该html文件,最简单的方法是使用 for Chrome 。这将解决这个问题。

Just change the url to http://localhost instead of localhost. If you open the html file from local, you should create a local server to serve that html file, the simplest way is using Web Server for Chrome. That will fix the issue.

我不在是我 2025-01-29 09:04:50

我将列出 3种不同的方法来解决此问题:

  1. 使用非常轻巧的 npm package :安装 live-server 使用 npm install -g install -g live-server 。然后,转到该目录打开终端和类型 live-server 并命中Enter,页面将通过 localhost:8080 提供。奖励:默认情况下还支持热重新加载。
  2. 使用轻量级的Google Chrome 由Google开发:安装应用程序,然后转到Chrome中的“应用”选项卡并打开应用程序。在应用程序中,将其指向右边的文件夹。您的页面将提供!
  3. 在Windows中修改Chrome快捷方式:创建Chrome浏览器的快捷方式。右键单击图标并打开属性。在属性中,编辑 target to “ C:\ Program Files(x86)\ Google \ Chrome \ Chrome \ application \ chrome.exe” - disable-web-security -user-data-data-data-data-data =“ C:/Chromedevsession” 并保存。然后使用Chrome使用 Ctrl+O 打开页面。注意:做使用此快捷方式进行常规浏览。

注意:使用 http:// 喜欢 http:// localhost:8080 ,以防您面临错误。

I'm going to list 3 different approaches to solve this issue:

  1. Using a very lightweight npm package: Install live-server using npm install -g live-server. Then, go to that directory open the terminal and type live-server and hit enter, page will be served at localhost:8080. BONUS: It also supports hot reloading by default.
  2. Using a lightweight Google Chrome app developed by Google: Install the app, then go to the apps tab in Chrome and open the app. In the app point it to the right folder. Your page will be served!
  3. Modifying Chrome shortcut in windows: Create a Chrome browser's shortcut. Right-click on the icon and open properties. In properties, edit target to "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:/ChromeDevSession" and save. Then using Chrome open the page using ctrl+o. NOTE: Do NOT use this shortcut for regular browsing.

Note: Use http:// like http://localhost:8080 in case you face error.

倾城花音 2025-01-29 09:04:50

使用 http:// https:// 创建URL

错误 localhost:8080

解决方案解决方案 http:// localhost:8080

Use http:// or https:// to create url

error: localhost:8080

solution: http://localhost:8080

我一向站在原地 2025-01-29 09:04:50

在Android应用程序中 - 例如,允许JavaScript可以通过 file:/// Android_asset/访问资产 - 使用 setallowfileafileAccessFromfileUrls(true)(true) 您从调用 getSettings() WebView 上获得。

In an Android app — for example, to allow JavaScript to have access to assets via file:///android_asset/ — use setAllowFileAccessFromFileURLs(true) on the WebSettings that you get from calling getSettings() on the WebView.

献世佛 2025-01-29 09:04:50

对我来说最快的方法是:
对于Windows用户,在解决Firefox问题上运行文件,或
如果您想对我使用Chrome最简单的方法是安装Python 3,则从命令提示符命令 Python -M http.server 然后转到 http:// localhost:8000/然后导航到您的文件

python -m http.server

fastest way for me was:
for windows users run your file on Firefox problem solved, or
if you want to use chrome easiest way for me was to install Python 3 then from command prompt run command python -m http.server then go to http://localhost:8000/ then navigate to your files

python -m http.server
旧街凉风 2025-01-29 09:04:50

简单的解决方案使用VS代码

我已经遇到了一段时间。大多数答案有效。但是我找到了一个不同的解决方案。如果您不想处理 node.js 或此处的任何其他解决方案,并且正在使用HTML文件(从另一个JS文件或Fetch JSON API的调用函数)尝试使用 live服务器扩展。

它使您可以轻松打开Live服务器。由于它创建 localhost 服务器,因此问题正在解决。您可以通过打开HTML文件并在编辑器上右键单击 Localhost 启动 ,然后单击使用Live Server 打开

它基本上是使用 http://localhost/index.html 而不是使用 file> file> file> file> file>:// ...

编辑

不必拥有 .html 文件。您可以使用快捷方式启动Live服务器。

hit (alt+l,alt+o)打开服务器和(alt+l,alt+c)停止服务器。 [在Mac, CMD+L,CMD+O CMD+L,CMD+C ]

希望它能帮助某人:)

Easy solution for whom using VS Code

I've been getting this error for a while. Most of the answers works. But I found a different solution. If you don't want to deal with node.js or any other solution in here and you are working with an HTML file (calling functions from another js file or fetch json api's) try to use Live Server extension.

It allows you to open a live server easily. And because of it creates localhost server, the problem is resolving. You can simply start the localhost by open a HTML file and right-click on the editor and click on Open with Live Server.

It basically load the files using http://localhost/index.html instead of using file://....

EDIT

It is not necessary to have a .html file. You can start the Live Server with shortcuts.

Hit (alt+L, alt+O) to Open the Server and (alt+L, alt+C) to Stop the server. [On MAC, cmd+L, cmd+O and cmd+L, cmd+C]

Hope it will help someone :)

就像说晚安 2025-01-29 09:04:50

如果您使用旧版本的Mozilla Firefox(2019年前),它将按预期工作,没有任何问题;

PS令人惊讶的是,旧版本的Internet Explorer&amp;边缘的工作也绝对很好。

If you use old version of Mozilla Firefox (pre-2019), it will work as expected without any issues;

P.S. Surprisingly, old versions of Internet Explorer & Edge work absolutely fine too.

永不分离 2025-01-29 09:04:50

更新:我亲自关闭 security.fileuri.strict_origin_policy_policy 在Firefox中通过关于:config 。它允许提取可以在我的本地HTML文件中工作,因此我可以在不必启动服务器的情况下测试工作。与Chrome不同,Firefox无需重新启动即可更改此政策。我不知道这可能会如何影响正常的浏览。我认为它仅影响您打开的本地.html文件。但是Firefox无论如何都不是我的主要浏览器,所以我只是将其保留。

对于那些没有python或node.js的窗户上的人,仍然有一个轻巧的解决方案: mongoose /strong>。

您所要做的就是将可执行文件拖到服务器的根部所在的任何地方,然后运行它。图标将显示在任务栏中,并将在默认浏览器中导航到服务器。

另外, z-wamp 是一个100%的便携式wamp,在单个文件夹中运行,很棒。如果您需要快速的PHP和MySQL Server,则可以选择。尽管自2013年以来就没有进行更新。现代替代方案是 laragon winnmp 。我没有测试过它们,但是它们是便携式的,值得一提的。我也是

另外,如果您只想要绝对的基础知识(HTML+JS),这是一个微小的PowerShell脚本,不需要安装或下载任何内容:

$Srv = New-Object Net.HttpListener;
$Srv.Prefixes.Add("http://localhost:8080/");
$Srv.Start();
Start-Process "http://localhost:8080/index.html";
While($Srv.IsListening) {
    $Ctx = $Srv.GetContext();
    $Buf = [System.IO.File]::OpenRead((Join-Path $Pwd($Ctx.Request.RawUrl)));
    $Ctx.Response.ContentLength64 = $Buf.Length;
    $Ctx.Response.Headers.Add("Content-Type", "text/html");
    $Buf.CopyTo($Ctx.Response.OutputStream);
    $Buf.Close();
    $Ctx.Response.Close();
};

此方法非常准确,它不能显示目录或其他奇特的东西。但是它处理了这些CORS错误。

将脚本保存为 server.ps1 ,并在项目的根部运行。它将在放置的目录中启动index.html。

Update: I personally turn off security.fileuri.strict_origin_policy in Firefox via about:config. It allows fetch to work in my local html files so I can test my work without having to start a server. Unlike Chrome, Firefox doesn't need to be restarted to change this policy. I have no clue how this may impact normal browsing; I assume it only affects local .HTML files you open. But Firefox is not my primary browser anyway, so I just leave it on.

For those on Windows without Python or Node.js, there is still a lightweight solution: Mongoose.

All you do is drag the executable to wherever the root of the server should be, and run it. An icon will appear in the taskbar and it'll navigate to the server in the default browser.

Also, Z-WAMP is a 100% portable WAMP that runs in a single folder, it's awesome. That's an option if you need a quick PHP and MySQL server. Though it hasn't been updated since 2013. A modern alternative would be Laragon or WinNMP. I haven't tested them, but they are portable and worth mentioning. I also was a fan of Uniform Server years ago; but it seems a bit dated, yet still around.

Also, if you only want the absolute basics (HTML+JS), here's a tiny PowerShell script that doesn't need anything to be installed or downloaded:

$Srv = New-Object Net.HttpListener;
$Srv.Prefixes.Add("http://localhost:8080/");
$Srv.Start();
Start-Process "http://localhost:8080/index.html";
While($Srv.IsListening) {
    $Ctx = $Srv.GetContext();
    $Buf = [System.IO.File]::OpenRead((Join-Path $Pwd($Ctx.Request.RawUrl)));
    $Ctx.Response.ContentLength64 = $Buf.Length;
    $Ctx.Response.Headers.Add("Content-Type", "text/html");
    $Buf.CopyTo($Ctx.Response.OutputStream);
    $Buf.Close();
    $Ctx.Response.Close();
};

This method is very barebones, it cannot show directories or other fancy stuff. But it handles these CORS errors just fine.

Save the script as server.ps1 and run in the root of your project. It will launch index.html in the directory it is placed in.

榆西 2025-01-29 09:04:50

我怀疑在某些答案中已经提到了它,但是我会稍微修改以使其具有完整的工作答案(更易于找到和使用)。

  1. 转到: https://nodejs.org/en/down/down/load/ 。安装nodejs。

  2. 通过命令提示 npm Install -G http-server

  3. 更改为您的工作目录,其中 index.html / youserome.html 居住。

  4. 通过运行命令 http-server -c-1

    启动您的HTTP服务器,

Open Open Web浏览器到 http:// localhost:8080
http:// localhost:8080/youserome.html - 取决于您的HTML文件名。

I suspect it's already mentioned in some of the answers, but I'll slightly modify this to have complete working answer (easier to find and use).

  1. Go to: https://nodejs.org/en/download/. Install nodejs.

  2. Install http-server by running command from command prompt npm install -g http-server.

  3. Change into your working directory, where index.html/yoursome.html resides.

  4. Start your http server by running command http-server -c-1

Open web browser to http://localhost:8080
or http://localhost:8080/yoursome.html - depending on your html filename.

倾其所爱 2025-01-29 09:04:50

当在使用本地目录的JSON文件的浏览器上加载HTML文件时,我会遇到此确切的错误。就我而言,我能够通过创建允许使用服务器静态内容的简单节点服务器来解决此问题。我在此其他答案

I was getting this exact error when loading an HTML file on the browser that was using a json file from the local directory. In my case, I was able to solve this by creating a simple node server that allowed to server static content. I left the code for this at this other answer.

高跟鞋的旋律 2025-01-29 09:04:50

它只是说该应用程序应在Web服务器上运行。我对Chrome遇到了同样的问题,我开始使用Tomcat并将其应用于那里,并且奏效了。

It simply says that the application should be run on a web server. I had the same problem with chrome, I started tomcat and moved my application there, and it worked.

心凉怎暖 2025-01-29 09:04:50

我建议您使用迷你服务器在Localhost上运行此类应用程序(如果您不使用某些内置服务器)。

这是一个非常简单的设置和运行:

https://www.npmjs.com/package/tiny-server

I suggest you use a mini-server to run these kind of applications on localhost (if you are not using some inbuilt server).

Here's one that is very simple to setup and run:

https://www.npmjs.com/package/tiny-server
¢好甜 2025-01-29 09:04:50

没有服务器,无法加载静态本地文件(例如:SVG)。如果计算机中安装了NPM/YARN,则可以使用“ http-serverrer”> http-serverrer

npm install http-server -g
http-server [path] [options]

或该项目文件夹中的打开终端,然后键入“ HS”。它将自动启动http live服务器。

Not possible to load static local files(eg:svg) without server. If you have NPM /YARN installed in your machine, you can setup simple http server using "http-server"

npm install http-server -g
http-server [path] [options]

Or open terminal in that project folder and type "hs". It will automaticaly start HTTP live server.

[浮城] 2025-01-29 09:04:50

当我下载页面以供离线视图时,经历了这一点。

我只需要删除 Integrity =“ *****” and crossorigin =“ Anonymous” 属性,从所有&lt; link&gt; and &lt; script&gt; 标签

Experienced this when I downloaded a page for offline view.

I just had to remove the integrity="*****" and crossorigin="anonymous" attributes from all <link> and <script> tags

伴随着你 2025-01-29 09:04:50

如果您坚持在本地运行 .html 文件,而不是与Web服务器一起使用,则可以通过使有问题的资源内联用来防止这些交叉原点请求进行。

我试图通过 file> file> file> file> file> file> file> file> file> file>。我的解决方案是更新我的构建脚本以替换&lt; script src =“ ...”&gt; 标签,用&lt; script&gt; ...&lt;/script&gt;
这是 Gulp 做到这一点的方法:

1。
运行 npm install -save-dev 到软件包 Gulp Gulp-Inline del

2。
创建 gulpfile.js 到根目录之后,添加以下代码(只需更改您适合您的任何适合您的文件路径):

let gulp = require('gulp');
let inline = require('gulp-inline');
let del = require('del');

gulp.task('inline', function (done) {
    gulp.src('dist/index.html')
    .pipe(inline({
        base: 'dist/',
        disabledTypes: 'css, svg, img'
    }))
    .pipe(gulp.dest('dist/').on('finish', function(){
        done()
    }));
});

gulp.task('clean', function (done) {
    del(['dist/*.js'])
    done()
});

gulp.task('bundle-for-local', gulp.series('inline', 'clean'))
  1. 要么运行 Gulp Bundle-for-local 或更新您的构建脚本以自动运行它。

您可以看到我的案例在这里的详细问题和解决方案。

If you insist on running the .html file locally and not serving it with a webserver, you can prevent those cross origin requests from happening in the first place by making the problematic resources available inline.

I had this problem when trying to to serve .js files through file://. My solution was to update my build script to replace <script src="..."> tags with <script>...</script>.
Here's a gulp approach for doing that:

1.
run npm install --save-dev to packages gulp, gulp-inline and del.

2.
After creating a gulpfile.js to the root directory, add the following code (just change the file paths for whatever suits you):

let gulp = require('gulp');
let inline = require('gulp-inline');
let del = require('del');

gulp.task('inline', function (done) {
    gulp.src('dist/index.html')
    .pipe(inline({
        base: 'dist/',
        disabledTypes: 'css, svg, img'
    }))
    .pipe(gulp.dest('dist/').on('finish', function(){
        done()
    }));
});

gulp.task('clean', function (done) {
    del(['dist/*.js'])
    done()
});

gulp.task('bundle-for-local', gulp.series('inline', 'clean'))
  1. Either run gulp bundle-for-local or update your build script to run it automatically.

You can see the detailed problem and solution for my case here.

如日中天 2025-01-29 09:04:50

对于 macos ...设置一个简单的启动,在您自己的 chrome ...

保存 中启用这些迷人的功能,以启用这些迷人的功能... plist ,名为 whyther aunplion.chrome.dev.mode.plist )) /code>具有与...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>launch.chrome.dev.mode</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Applications/Google Chrome.app/Contents/MacOS/Google Chrome</string>
        <string>-allow-file-access-from-files</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

相似的内容应在启动时启动。但是,您可以随时使用终端命令

laundingctl load -w〜/Library/ launchagents/lunage.chrome.dev.mode.plist

tada!

For all y'all on MacOS... setup a simple LaunchAgent to enable these glamorous capabilities in your own copy of Chrome...

Save a plist, named whatever (launch.chrome.dev.mode.plist, for example) in ~/Library/LaunchAgents with similar content to...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>launch.chrome.dev.mode</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Applications/Google Chrome.app/Contents/MacOS/Google Chrome</string>
        <string>-allow-file-access-from-files</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

It should launch at startup.. but you can force it to do so at any time with the terminal command

launchctl load -w ~/Library/LaunchAgents/launch.chrome.dev.mode.plist

TADA! ???? ???????? ???? ????????

一生独一 2025-01-29 09:04:50

嗯。我刚刚发现了一些官方单词“试图加载使用Dojo/文本插件的未构建的远程AMD模块,由于跨原始安全性限制而导致失败。构建系统。)“

er. I just found some official words "Attempting to load unbuilt, remote AMD modules that use the dojo/text plugin will fail due to cross-origin security restrictions. (Built versions of AMD modules are unaffected because the calls to dojo/text are eliminated by the build system.)" https://dojotoolkit.org/documentation/tutorials/1.10/cdn/

叹梦 2025-01-29 09:04:50

加载本地文件的一种方法是在项目文件夹中使用它们,而不是在项目文件夹外部使用。在您的项目示例文件下创建一个文件夹,类似于我们为图像创建的方式,并替换了使用项目路径以外的完整路径并使用项目文件夹下的文件相对URL的部分。
它对我有用

One way it worked loading local files is using them with in the project folder instead of outside your project folder. Create one folder under your project example files similar to the way we create for images and replace the section where using complete local path other than project path and use relative url of file under project folder .
It worked for me

十年九夏 2025-01-29 09:04:50
  • 安装用于Java的本地Web服务器,例如php,您可以使用lamp等,
  • 将json文件放在公共访问的应用服务器目录中
  • “

  • sstatic.net/ahzti.png“ rel =“ nofollow noreferrer”> 访问该文件
  • Install local webserver for java e.g Tomcat,for php you can use lamp etc
  • Drop the json file in the public accessible app server directory
  • List item

  • Start the app server,and you should be able to access the file from localhost

再可℃爱ぅ一点好了 2025-01-29 09:04:50

对于Linux Python用户:

import webbrowser
browser = webbrowser.get('google-chrome --allow-file-access-from-files %s')
browser.open(url)

For Linux Python users:

import webbrowser
browser = webbrowser.get('google-chrome --allow-file-access-from-files %s')
browser.open(url)
何以心动 2025-01-29 09:04:50

为此,我的问题缺少'/'示例:
jQuery-1.10.2.js:8720 xmlhttprequest不能加载 http:// localhost:xxx/product/getlist_taglabels/

我希望我希望这对谁有帮助解决这个问题。

Many problem for this, with my problem is missing '/' example:
jquery-1.10.2.js:8720 XMLHttpRequest cannot load http://localhost:xxxProduct/getList_tagLabels/
It's must be: http://localhost:xxx/Product/getList_tagLabels/

I hope this help for who meet this problem.

马蹄踏│碎落叶 2025-01-29 09:04:50

使用以下HREF,我还可以重新创建此错误消息:

<a href="javascript:">Example a tag</a>

在我的情况下,正在使用一个标签来获取“指针光标”,并且该事件实际上是由点击事件的一些jQuery控制的。我删除了HREF并添加了适用的类:

cursor:pointer;

I have also been able to recreate this error message when using an anchor tag with the following href:

<a href="javascript:">Example a tag</a>

In my case an a tag was being used to get the 'Pointer Cursor' and the event was actually controlled by some jQuery on click event. I removed the href and added a class that applies:

cursor:pointer;

偏爱你一生 2025-01-29 09:04:50

科尔多瓦实现了这一点。我仍然不知道科尔多瓦的表现如何。它甚至没有通过Enewernceptrequest。

后来我发现从本地加载任何文件的关键是:mywebview.getSettings()。setallowuniversalaccessalaccessfromfileurls(true);

当您要访问任何HTTP资源时,WebView将使用选项方法进行检查,您可以通过webViewClient.shoundinderceptrequest通过返回响应来授予访问权限,并且对于以下get/post方法,您只需返回null。

cordova achieve this. I still can not figure out how cordova did. It does not even go through shouldInterceptRequest.

Later I found out that the key to load any file from local is: myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);

And when you want to access any http resource, the webview will do checking with OPTIONS method, which you can grant the access through WebViewClient.shouldInterceptRequest by return a response, and for the following GET/POST method, you can just return null.

等风来 2025-01-29 09:04:50

如果要搜索firebase托管的解决方案,则可以

firebase cli

这就是我来这里的目的,所以我想我只是把它留在这里以帮助喜欢。

If you are searching for a solution for Firebase Hosting, you can run the

firebase serve --only hosting command from the Firebase CLI

That's what I came here for, so I thought I'd just leave it here to help like ones.

一身骄傲 2025-01-29 09:04:50

如果您使用的VS代码只是尝试在其中加载实时服务器。立即解决了我的问题。

If your using VS code just trying loading a live server in there. fixed my problem immediately.

八巷 2025-01-29 09:04:50

URL应该像:

 createUserURL = "http://www.localhost:3000/api/angular/users"

而不是:

 createUserURL = "localhost:3000/api/angular/users"

url should be like:

 createUserURL = "http://www.localhost:3000/api/angular/users"

instead of:

 createUserURL = "localhost:3000/api/angular/users"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文