Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-origin request for local file

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.

Thanks

like image 290
User4870 Avatar asked Apr 19 '17 10:04

User4870


2 Answers

If you are using VS Code, the Live Server extension might help you. It resolved a cross-origin issue I was having when editing a webpage.

https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer

like image 56
JamesBock Avatar answered Sep 17 '22 12:09

JamesBock


The simplest way to allow this in Firefox is to navigate to about:config, look for the privacy.file_unique_originsetting and toggle it off.

Essentially, Firefox used to treat local files from the same directory as being from the same source, thus CORS was happily satisfied. That behavior changed after CVE-2019-11730 was discovered.

It worked fine for me on 84.0.1 on Arch. Just be sure to turn it off when not locally debugging.

Source

like image 22
koepnick Avatar answered Sep 18 '22 12:09

koepnick