For me, I understood fetch better than ajax but they don't want me to use fetch! They want me to stick to ajax apparently as ajax will most likely to work all the time but where as fetch won't always be supported due it being newer... 😫
So I understand why there would be an await before a fetch call, but is it really necessary to put an await before the "response.json()"? Wouldn't that function call be instantaneous since it's not getting anything outside of JS? Or do you just put an await before every function call of a promise?
the response.json() method returns a Promise that resolves with the result of parsing the body text as JSON. Therefore, you do need to use await with it to ensure that the parsing completes before the next line of code runs. If you don't use await, the user variable would hold a Promise rather than the actual parsed JSON data.
Really thanks! This was exactly what I wanted to learn. One more question, Which of the two last options is the best? (fetch.then or fetch async/await).
All good 🙂 either one is fine, there's no "best" only different ways to do it. If you want wider browser support then stick to .then - check out Can I Use website to see browser compatibility
hello reallyawesome explanation ; i get wait and then relation much clearer now and compared to callback ajax; i will keep practicing; i want to maention then these catch error functions i dont like cuz all they do is bring you to the line where the catch code was written not tothe actual line error; so i leave that catch error out so the defaut web console erro bring me to the actial error line; unless you know how to actully display the line error : thxz Lisa
Brother! You maded it so simple that even a kid in prmary school will understand. Thanks
Something I always wanted to know
Thanks!
Thanks! very clear and so beginner friendly
Thank you! I have been trying to understand the difference and you explained it very well.
Your tutorials are help ful.
Love from hargiesa somaliland 💕🙏
This is some good stuff. Thanks!
Now isnt using ajax allows you to load information without refreshing?
i am working on a uni project right now in php and i need to use ajax in some parts, can i use fetch api with database?
pull data from an external file on desktop with fetch api?
Thank you for explaination
Awesome as always 👍😀
Nice, but how to use timeout, f.i. if server does not response for >10s ?
For me, I understood fetch better than ajax but they don't want me to use fetch! They want me to stick to ajax apparently as ajax will most likely to work all the time but where as fetch won't always be supported due it being newer... 😫
Thanks!
Could you please include the code under your videos pls? (I mean via a link obviously)
So I understand why there would be an await before a fetch call, but is it really necessary to put an await before the "response.json()"? Wouldn't that function call be instantaneous since it's not getting anything outside of JS? Or do you just put an await before every function call of a promise?
the response.json() method returns a Promise that resolves with the result of parsing the body text as JSON. Therefore, you do need to use await with it to ensure that the parsing completes before the next line of code runs. If you don't use await, the user variable would hold a Promise rather than the actual parsed JSON data.
Really thanks! This was exactly what I wanted to learn. One more question, Which of the two last options is the best? (fetch.then or fetch async/await).
All good 🙂 either one is fine, there's no "best" only different ways to do it. If you want wider browser support then stick to .then - check out Can I Use website to see browser compatibility
Personally i prefer async/await func as it looks more cleaner. But both are good as they share the same purpose.
@@deewastamang9135 after 11 months lol, now I'm a Senior developer lol. Thanks btw
@@amirrezaamini9907 That's impressive! Good to know.
Great vid!!
do you just add .json to a link ?
One annoying part about native fetch method, it cant handle file upload progress.
What local server you use for this tutorial?
I use Apache
hello reallyawesome explanation ; i get wait and then relation much clearer now and compared to callback ajax; i will keep practicing; i want to maention then these catch error functions i dont like cuz all they do is bring you to the line where the catch code was written not tothe actual line error; so i leave that catch error out so the defaut web console erro bring me to the actial error line; unless you know how to actully display the line error : thxz Lisa
thnx this help a log even its already 2023 haha
Thanks
Welcome
Man, I hate ajax. This truly is a game-changer.
Sorry Ajax, we have to break up
_sad AJAX noises_