JavaScript Tip: Loading a Local JSON File without Fetch

JavaScript Tip: Loading a Local JSON File without Fetch

All Things JavaScript, LLC

2 года назад

39,905 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

MutaMente
MutaMente - 24.09.2023 19:42

pouts!! que montagem huahuahuahuauha
muito bom xD

Ответить
Roumen1
Roumen1 - 21.09.2023 22:27

Thank you so much!

Ответить
Assiel Nahum Reyes Umaña
Assiel Nahum Reyes Umaña - 05.09.2023 22:25

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file///C:/XXX/app/js/app.json 🥲

Ответить
4estral
4estral - 19.05.2023 14:54

At this time, Firefox still doesn't support assertions. Otherwise this works great.

Ответить
Everest Obot
Everest Obot - 23.04.2023 19:26

Local Filesystem Detected !
Put this to your header:
<script type="text/javascript" src="js/extensions/revolution.extension.slideanims.min.js"></script>
<script type="text/javascript" src="js/extensions/revolution.extension.actions.min.js"></script>
<script type="text/javascript" src="js/extensions/revolution.extension.layeranimation.min.js"></script>
<script type="text/javascript" src="js/extensions/revolution.extension.navigation.min.js"></script>
<script type="text/javascript" src="js/extensions/revolution.extension.parallax.min.js"></script>

Ответить
Александр Васильев
Александр Васильев - 31.03.2023 21:01

thanks a lot!

Ответить
Xc4
Xc4 - 26.03.2023 19:45

I got an error "Uncaught SyntaxError: Unexpected token ':' " for my json file

Ответить
Mattia Ruberto
Mattia Ruberto - 13.03.2023 09:13

Mind-blowing!!!

Ответить
Prodip Kumar Shil
Prodip Kumar Shil - 02.03.2023 10:18

thank you sir, it helps a lot

Ответить
umangternate
umangternate - 01.03.2023 03:47

I got "import assertions are not currently supported"

Ответить
perdu0609
perdu0609 - 28.02.2023 23:30

Does anyone have an error "Cannot use import statement outside a module" ?

Ответить
Александр Штыб
Александр Штыб - 10.02.2023 22:32

Thank you very much! You helped me out

Ответить
Ilich
Ilich - 07.02.2023 22:57

Thx, such useful info!
Warmest greetings from Ukraine!

Ответить
Oreki
Oreki - 09.01.2023 02:34

newbie here! Is it possible to update the content of the JSON file?

Ответить
JAYANT AGARWAL
JAYANT AGARWAL - 05.01.2023 12:14

you really saved my day

Ответить
frechdaXchs
frechdaXchs - 20.12.2022 11:19

does not work for me. Need to access a local json file without a (live) server or user input. Seems impossible...

Ответить
Ivan Gutowski-Smith
Ivan Gutowski-Smith - 05.12.2022 13:34

Thanking for saying you would link something in the description, and remembering to link it

Ответить
Mikhail Webb
Mikhail Webb - 22.11.2022 02:24

Everything else seems to work for me now. BUT, I need the .json file to read as an object or variable like dictionary so i can process the data from it in Javascript. How can i store the data that is read into a variable like object? I need it to be able to read similar to how python read dictionaries

Ответить
Nyarlathotep The Crawling Chaos
Nyarlathotep The Crawling Chaos - 11.10.2022 09:47

I have a question. How can I import data of a nested array in the JSON
i have made a script to pull data from an SQL server, which works fine but outputs a file set like this
[
[
{
Objects
}
A bunch more objects
]
]

And I've been using a script I've found to display it in HTML, but the script doesn't understand the nested array

Ответить
HollowsDarkness
HollowsDarkness - 11.10.2022 06:22

Then could you console.log(users.name) and it print out the ane of the users?

Ответить
Rakshit Deshmukh
Rakshit Deshmukh - 27.09.2022 15:57

I've been searching for hours and ended up on this video. Thanks a million tons!

Ответить
Darren Lo
Darren Lo - 28.08.2022 07:06

This only works with Chrome. It does not work with FF just a heads up. If you try to run this with FF you will have issues and it will not load the array since FF does not support import assertions.

Ответить
Angel Garcia
Angel Garcia - 19.08.2022 20:38

Thank you!

Ответить
aver try
aver try - 31.07.2022 13:26

Thanks, but your link to fetch, actually links to this video.

Ответить
AHMED ALSAGIR
AHMED ALSAGIR - 13.07.2022 03:24

i can't stop watch 3 hour continuous, amazing

Ответить
HIRNREICH
HIRNREICH - 05.07.2022 18:13

This is exactly what I was looking for ... makes my code so much more streamlined!

Ответить
V
V - 25.06.2022 18:04

Many thanks for this, I’ve sometimes wanted to try some stuff out using a mock data file i JSON format, but I’ve usually given up after getting that second error message.
Now I know why it happens.

Ответить
Jay from CT
Jay from CT - 16.06.2022 01:08

Thanks! Excellent video. This method is great for when your app’s json data is on the same server as the app itself. No need to wait for the json. Promises can be avoided making coding easier/less complex

Ответить
Karlstens
Karlstens - 16.06.2022 00:50

Thanks for sharing this. I found this example to work well when using Google Chrome as the target, but when using FireFox - it reports; "Uncaught SyntaxError: import assertions are not currently supported".

Ответить