Allow Google Chrome to Use Xmlhttprequest to Load a Url from a Local File

Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

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.

XMLHttpRequest cannot load file:///... Preflight response is not successful error

XMLHttpRequest dont work with file protocol only with http, data, chrome, chrome-extension, https.

you need to host your file or use something like this link bellow to allow this.

Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

In Safari 11 file protocol access are limited.

[CORS and cross origin access from file:// are now blocked unless Disable Local File Restrictions is selected from the Develop menu.]

Cannot open local file - Chrome: Not allowed to load local resource

We use Chrome a lot in the classroom and it is a must to working with local files.

What we have been using is "Web Server for Chrome". You start it up, choose the folder wishing to work with and go to URL (like 127.0.0.1:port you chose)

It is a simple server and cannot use PHP but for simple work, might be your solution:

https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

XMLHttprequest not working on local host while running chrome without security

I have tried and the code is working fine.

Maybe you can't see the data due to a parsing error.

The only thing I changed is adding the closing square brackets in the JSON file and removing the last comma.

JSON code below:

{
"countries": [
{
"Country name": "China",
"Flag": "CN",
"Population": 1395380000
},
{
"Country name": "India",
"Flag": "IN",
"Population": 1338677000
}
]
}

I suggest not to use Chrome with flag disable-web-security enabled; instead (on VSCode) install the Live Server extension -> open the HTML file and launch the test server.

Simple as it should be without problematic errors:)

Hope it helps :)

Cross origin requests are only supported for HTTP. error when loading a local 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.

Loading local content through XHR in a Chrome packaged app

Yes, it's totally possible, and it's easy. Here's a working sample. Try starting with this, confirm that it works, and then add back in your own code. If you hit a roadblock and come up with a more specific question than whether XHRs work in packaged apps, you might want to ask a new question.

manifest.json:

{
"name": "SO 15977151 for EggCup",
"description": "Demonstrates local XHR",
"manifest_version" : 2,
"version" : "0.1",
"app" : {
"background" : {
"scripts" : ["background.js"]
}
},
"permissions" : []
}

background.js:

chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create("window.html",
{ bounds: { width: 600, height: 400 }});
});

window.html:

<html>
<body>
<div>The content is "<span id="content"/>"</div>
<script src="main.js"></script>
</body>
</html>

main.js:

function requestListener() {
document.querySelector("#content").innerHTML = this.responseText;
};

onload = function() {
var request = new XMLHttpRequest();
request.onload = requestListener;
request.open("GET", "content.txt", true);
request.send();
};

content.txt:

Hello, world!


Related Topics



Leave a reply



Submit