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

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:
• Access-Control-Allow-O...
Join this channel to get access to perks:
/ @dcode-software
For your reference, check this out:
developer.mozilla.org/en-US/d...
💜 Join my Discord Server:
/ discord
🎨 Download my Visual Studio Code theme:
marketplace.visualstudio.com/...
Support me on Patreon:
/ dcode
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

Пікірлер: 180

  • @antoniofuller2331
    @antoniofuller23313 жыл бұрын

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

  • @smoothbeak
    @smoothbeak3 жыл бұрын

    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)

  • @MarkKathrynVegera
    @MarkKathrynVegera2 жыл бұрын

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

  • @chatebillychilima6762
    @chatebillychilima67622 жыл бұрын

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

  • @mounir101
    @mounir1013 жыл бұрын

    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.

  • @chembetikarunakar814

    @chembetikarunakar814

    Жыл бұрын

    Without liveserver can we do this

  • @ScreenPrintR
    @ScreenPrintR2 жыл бұрын

    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.

  • @jassi1211
    @jassi12112 жыл бұрын

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

  • @pavelromanov8833
    @pavelromanov88332 жыл бұрын

    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!

  • @RIGARR
    @RIGARR3 жыл бұрын

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

  • @willturner9849
    @willturner98497 ай бұрын

    Thank you so much! That was really helpful!

  • @christianrivera1568
    @christianrivera15682 жыл бұрын

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

  • @Olalekan.Ekundayo

    @Olalekan.Ekundayo

    Жыл бұрын

    So, I found someone like me that was stuck with this error message for weeks 😂

  • @alexthewebdesigner1856
    @alexthewebdesigner18567 ай бұрын

    Thanx for posting this Bro. It was a great help!

  • @joshuacushing2858
    @joshuacushing28582 жыл бұрын

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

  • @changleding4296
    @changleding429610 ай бұрын

    This really helps me a lot! Truly appreciate!!!

  • @Felix-vu9tz
    @Felix-vu9tz Жыл бұрын

    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!

  • @ScreenPrintR
    @ScreenPrintR2 жыл бұрын

    Thank you. This was extremely helpful Kudos to you.

  • @youarepopo
    @youarepopo3 жыл бұрын

    Thanks a lot! Great Explanation.

  • @leonardosolorio9609
    @leonardosolorio9609 Жыл бұрын

    Thank you bro, your explanation saved me loads of time! Thanks!!

  • @itzigma9176
    @itzigma91762 жыл бұрын

    Pretty awesome!! Great Explanation. Well Thanks a lot.

  • @einsteinwallah2
    @einsteinwallah2 Жыл бұрын

    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

  • @Olalekan.Ekundayo
    @Olalekan.Ekundayo Жыл бұрын

    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 😄

  • @my.b707

    @my.b707

    11 ай бұрын

    The same, that slow my learning an I was sad. Now I can continue

  • @cloudzero2049
    @cloudzero20498 ай бұрын

    I'm over here training neural networks and getting ready to pull my hair out because CORS wouldn't let me load my trained models (ML5.js library). I let out a huge sigh of relief when you said VS Code has a server extension, I was worried I was going to have to design a Node.js overlay. Every things working, thank you so much.

  • @davidpadron8329
    @davidpadron8329 Жыл бұрын

    Thanks man for the explanation. This helped me to solve the problem 🙂👍

  • @redpill5008
    @redpill50083 жыл бұрын

    Thank you a lot. It worked!

  • @almohaiminfarabi9181
    @almohaiminfarabi9181 Жыл бұрын

    Is there any way to do it without live server extention?

  • @AhmedMohamed-sn1rp
    @AhmedMohamed-sn1rp Жыл бұрын

    Thank you so much It really helped me

  • @delegatewu
    @delegatewu Жыл бұрын

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

  • @Harry-gc8kb
    @Harry-gc8kb Жыл бұрын

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

  • @juliuspaige5173
    @juliuspaige51732 жыл бұрын

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

  • @sunnylarosa4700
    @sunnylarosa4700 Жыл бұрын

    Thankyou! It's helping😁

  • @blazi_0
    @blazi_03 жыл бұрын

    Is live server like local host ?or they're different stuff ?

  • @KinTsume
    @KinTsume2 жыл бұрын

    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?

  • @alin-alexandru-peter
    @alin-alexandru-peter2 жыл бұрын

    maaaaaaaaaaaaan your the best !!! I need your tutorial for the timer and i was getting this error you fixed it for me!1 great job ! you and coding train:))) are my favorite developers ever.

  • @rangabharath4253
    @rangabharath42533 жыл бұрын

    Awesome as always 👍😀

  • @user-mf5wb5qt8u
    @user-mf5wb5qt8u2 жыл бұрын

    Thank you so much. :) It worked for me

  • @alexhoubak5869
    @alexhoubak58692 жыл бұрын

    Very helpful thanks!

  • @kalagan
    @kalagan10 ай бұрын

    Thank you, very helpful

  • @romainba4098
    @romainba40982 жыл бұрын

    You helped us a lot, dude

  • @topsportscoverage9257
    @topsportscoverage92572 жыл бұрын

    Thanks for the great video!

  • @lindaoktavianty2688
    @lindaoktavianty26883 жыл бұрын

    Thank youu so much.. your video is so helping 😭

  • @t_sem84
    @t_sem84 Жыл бұрын

    thanks so much really apreciated

  • @Huszan
    @Huszan11 ай бұрын

    Thank You man! You are a life saver!

  • @dopamine_Seeker
    @dopamine_Seeker2 жыл бұрын

    Thank God! Randomly I found your video. Thank u 😊

  • @michaelwhite278
    @michaelwhite278 Жыл бұрын

    Did you do the voice for the whale in the beached whale / chips bru video?

  • @thenarfer
    @thenarfer3 жыл бұрын

    Fantastic video! I hope this will solve my problem. Will try to upload my files to my server and see if the problem still occurs.

  • @short_facts_entertaining
    @short_facts_entertaining Жыл бұрын

    Great! Was super helpful

  • @LearnWithSadik165
    @LearnWithSadik1652 жыл бұрын

    Thanks, it's helpful for me.

  • @baqsinternacional975
    @baqsinternacional975 Жыл бұрын

    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

  • @manojkolhe8221
    @manojkolhe82212 жыл бұрын

    thank u buddy, its very simple

  • @anthonysanchez119
    @anthonysanchez1192 жыл бұрын

    te lo agradezco mucho estaba pariendo y pujando por ese error, pero gracias a ti lo he corregido. Awesome, thanks

  • @leomussa3650
    @leomussa36503 жыл бұрын

    Thank you so much...amazing video

  • @soufianetaku3137
    @soufianetaku3137 Жыл бұрын

    thanks man it's really working

  • @tentorias8344
    @tentorias83442 жыл бұрын

    Oh man, thank you so much, you save my life.

  • @umangupadhyay4335
    @umangupadhyay4335 Жыл бұрын

    appriciated man .. thanks😇

  • @clutchmasterman
    @clutchmasterman2 жыл бұрын

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

  • @karlee8608
    @karlee86082 жыл бұрын

    Thank you dCode. You just solved it issue

  • @vivekchavan9926
    @vivekchavan9926 Жыл бұрын

    thanks for the help !

  • @HonduranHunk
    @HonduranHunk Жыл бұрын

    Saved me what would have been hours of scouring the internet. Thank you so much

  • @jossuer7124
    @jossuer71242 жыл бұрын

    If I dont want to use a web server?

  • @raphaelmatos4961
    @raphaelmatos49612 жыл бұрын

    Thanks for your help.

  • @marhlenz6476
    @marhlenz6476 Жыл бұрын

    Thanks man, excellent explanation.

  • @PrincessCarrieGraham
    @PrincessCarrieGraham3 жыл бұрын

    Modules in vanilla JavaScript produce the same error, BTW :-) and you totally rawk, because this worked on that too. Thank you.

  • @sammyj6077
    @sammyj6077 Жыл бұрын

    Thanks so much!!!!! 🙏

  • @krishshah3974
    @krishshah39742 жыл бұрын

    yo, thank you so much! :D

  • @SameerAbbasMughal
    @SameerAbbasMughal2 жыл бұрын

    Thank You Sir this video is very help full for me Thank altos!

  • @kamrantailor
    @kamrantailor2 жыл бұрын

    Thanks this helped me a lot

  • @imaansarwar2314
    @imaansarwar2314 Жыл бұрын

    Sir i am still getting error. while trying to add form data to google sheet

  • @aashapun6533
    @aashapun6533 Жыл бұрын

    Thank you soo much!

  • @csf4442
    @csf4442 Жыл бұрын

    thanks so much for this! you saved my bacon!

  • @ourielperez1646
    @ourielperez16462 жыл бұрын

    Thank you very much!

  • @nisenobody8273
    @nisenobody8273 Жыл бұрын

    Oh my lord, thank you! As a rookie this was being a truly headache.

  • @WaheedRafiq
    @WaheedRafiq3 жыл бұрын

    If you were standing in front of me, I would have kiss you buddy, spent like 2 days trying to fix this issue, and posted comments on stack flow for help you explained it well, easy to follow and for someone who is Dyslexic your tutorial was disable people-friendly too. well done.

  • @vicerogi
    @vicerogi2 жыл бұрын

    I'm used to active live server, but this time I didn't cause I thought there will be some problem with scss ( it is the first time with this preprocessor) And I was searching different solutions. I did not expect it at all jajaj my gosh, thanks indeed!!

  • @HAPPYLUCIA
    @HAPPYLUCIA Жыл бұрын

    You are the best. You save my time a lot. Many thanks!!

  • @nathanbennett9999
    @nathanbennett99992 жыл бұрын

    Thank you!

  • @lamegov
    @lamegov Жыл бұрын

    life saver thank you

  • @azraiputrabarumundaulay2082
    @azraiputrabarumundaulay20822 жыл бұрын

    thank u ser, it works

  • @mandavijayaraju2140
    @mandavijayaraju2140 Жыл бұрын

    It's working for me.thanks

  • @angelarojastovar8780
    @angelarojastovar87803 жыл бұрын

    Ty, you saved my life.

  • @BlueJhonny777
    @BlueJhonny777 Жыл бұрын

    works for me, thanks ; )

  • @20sinngamkhaidem86
    @20sinngamkhaidem86 Жыл бұрын

    Super Helpful

  • @nakeebabowes9735
    @nakeebabowes97358 ай бұрын

    Thanks a lot!!!!

  • @dontcare989
    @dontcare989 Жыл бұрын

    thx, u rly helps me

  • @dcode-software

    @dcode-software

    Жыл бұрын

    YOu're very welcome

  • @vadym1316
    @vadym1316 Жыл бұрын

    Excellent!

  • @khushisingh3028
    @khushisingh3028 Жыл бұрын

    Helpful!!!

  • @expauloczar
    @expauloczar Жыл бұрын

    Very good!

  • @DJMIKE20
    @DJMIKE20 Жыл бұрын

    Can you show how to solve this issue with the fetch method ?

  • @albertmartinezp
    @albertmartinezp3 жыл бұрын

    really simple and helpful, thanks so much

  • @i.am.bot.
    @i.am.bot.2 жыл бұрын

    Is this only for the websites I own or can I edit other websites using this method?Because I am facing some problem in sending pictures through instagram dm in instagram web I don't know why it's happening but it's a major issue for me and when I opened developer options it said that it was blocked by CORS policy,so I just wanted to know if there is any way to fix it and I literally have no idea about it so if you can make a video on it, then it would be really helpful.Please help🙏🙏

  • @nahuelgarcia0
    @nahuelgarcia02 жыл бұрын

    thanks brother you are the best

  • @SouravDas-ko9px
    @SouravDas-ko9px4 ай бұрын

    thanks man!

  • @messi._
    @messi._11 ай бұрын

    thx alot dude the extension shit is the simplest

  • @mpakasoul
    @mpakasoul Жыл бұрын

    Thank man you saved me

  • @ashmandeepkaur9392
    @ashmandeepkaur9392 Жыл бұрын

    I am already using live server in vs code but still getting this error. Can anyone help??

  • @aviuvaydov5690

    @aviuvaydov5690

    Жыл бұрын

    were you able to figure it out? I'm getting the same error

  • @michaelharyanto8220
    @michaelharyanto8220 Жыл бұрын

    Thanks man

  • @catz6457
    @catz6457 Жыл бұрын

    What about in GeoServer

  • @rezakhani8627
    @rezakhani8627 Жыл бұрын

    thank you ❤️

  • @116pankajmanral7
    @116pankajmanral79 ай бұрын

    thx a lot a was with this error for 1 week

  • @chaimsteinberg5010
    @chaimsteinberg50102 жыл бұрын

    Thank you

  • @Einfach_Dave
    @Einfach_Dave2 жыл бұрын

    thanks mate :D