How To Fix: 'null has been blocked by CORS policy' Error in JavaScript AJAX

preview_player
Показать описание
In today's video I'll be showing you how to fix the common CORS policy error which reads: ... from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported etc.

The problem is that you are most likely serving your HTML directly from your system, whereas instead you should be using a web server to serve your HTML, CSS, JavaScript or images.

A similar video on CORS:

Join this channel to get access to perks:

For your reference, check this out:

💜 Join my Discord Server:

🎨 Download my Visual Studio Code theme:

Support me on Patreon:

Follow me on Twitter:
@dcodeyt

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

I hate when they say "a very simple fix" lol

antoniofuller
Автор

When running that live server option in Visual Studio Code what's the keyboard shortcut for macOS to open up that panel? (he uses F1 on windows)

smoothbeak
Автор

Pretty awesome! I think every programmer had faced this problem before. Even I faced it as well and fixed it by using live server extension. Thanks so much bro for helping people to solve this issue.

mounir
Автор

Excellent and thank you for saving me another two hours of checking my code!

MarkKathrynVegera
Автор

Do I have to re-save my file in VS code? When I hit enter after doing the f1 I get a message on the bottom of vs that says open workspace.

ScreenPrintR
Автор

You man are a live safer. I've been banging my head for the past 3 hours and I feel relieved to have finally solved my problem. Thank you very much sir!

pavelromanov
Автор

woah! what a coincidence! I was just searchin' to fix this problem and got your video just uploaded

RIGARR
Автор

Perfectly summed up.... Easy and great fix. Thanks bruv

chatebillychilima
Автор

ok so file on hard drive with extension html or htm or any other cannot access pages from (say) a news or literature site but what if i am writing an android app using cordova platform ... once i finish writing app following your work arounds and i upload app will it work on any android which has "bought" from app store? ... remember person who "buys" just gets app ... will ajax or fetch still work because no server is running on android device of buyer afaik ... my code is not for a client's website but for a device like android ... when it is game like wordle hosted on nytimes website's games page it is still an access from server to server but when an app is running on an android device it is running exactly like a file from storage just like your error giving file ... please correct me if i am wrong

einsteinwallah
Автор

I'm having the same error but i'm using fetch(). I tried to load the page with live server but still doesn't work. Any advise?

KinTsume
Автор

Excellent explanation. Simple and short.. Easy to understand. Thnx man 👍🏻

jassi
Автор

thanks man, helped with starting my journey learning react, I was getting pretty frustrated as I wasnt even able to print hello world but now i should be able to actually get going, thanks!

Felix-vutz
Автор

This video is the response to my 2 weeks problem. Thank you sooo much!

christianrivera
Автор

How do you fix it if downloading a webserver is not an option?

juliuspaige
Автор

Hi, thank you for the video, my problem is a bit diferent, my cliente need the site to run offline in a company, and he can´t install the server in machines, because security compliance, how can i fix that? i´ve been trying this for more then 24 hours. I´ve created a bat file to open navigators without security in anonimous mode, however that´s not the ideal

baqsinternacional
Автор

but then whuy do you get the error if you fetch it from your own harddrive?

Harry-gckb
Автор

Wow! You just gave me a solution to the error message I have been encountering for weeks now, and has slow down my learning... Thank you very much, you deserved a like and a subscribe from me 😄

Olalekan.Ekundayo
Автор

problem is this only works for the .html alone. no other .js or .css file in the folder, which ofc breaks the project

clutchmasterman
Автор

Thanks so much! You saved me a lot of time and frustration!

joshuacushing
Автор

This video fixed my javascript csv loading problem too. Thank you very much.

delegatewu