Learn XML HTTP Requests in JavaScript | AJAX Tutorial




XML Http Requests (AJAX) allows you to send and receive data from external files within your Javascript code without refreshing the page or re-running your script.

In this video we look at how to create a request and then download the data, inserting it into the HTML body.

For your reference:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Follow me on Twitter @dcode

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

Original source


23 responses to “Learn XML HTTP Requests in JavaScript | AJAX Tutorial”

  1. i keep getting this error:

    index.html:30 Access to XMLHttpRequest at 'file:/…./dom.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

    Any idea what I'm doing wrong?

  2. Hi, nice video. I did exactly what you did and I get the below error. What do you think is the issue?

    mexico.js:29 Access to XMLHttpRequest at 'file:///C:/Users/imedi3/Documents/Web%20Reports/Mexico%20Triggers/prueba.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

    (anonymous) @ mexico.js:29

  3. Thank you for this video very much. It fits very well when you read a little bit of the W3Schools page and I was still a little confused but you cleared all of that up and I thank you for that. I also believe in your xhr.readystatechange function you can use this.readystate and this.status instead of xhr.readystate or xhr.status. Thank you for your help though.

  4. I'm trying to finish watching but your pretentious SUPER-DUPER tactile feedback , "I'm a real programmer", keyboard is annoying as $h!t3. You people think you're superior because your keyboard requires a million JOULES to type one letter. Terrible

  5. Good but you are no longer allowed to make xhr requests sync (false parameter). See console error infor in chrome for more information. We have to use Worker.class to do this. Im not sure how to solve it. Would be great to get another video about it.

  6. Very Great Video! Codecademy doesn't even go into any detail or depth as for the purpose for the actual commands used. Really helped understanding the process more. Thanks for the great content and tutorial man! 🙂

  7. Firstly thanks for the video. To me though, it seems more logical to put the xhr open and send lines before the function. I have to admit I’ve never seen it done this way. But wouldn’t it make more sense to make the request, send it, then run the function to check all is okay and display? Of course it doesn’t matter as the function can sit anywhere, but in terms of logical programming wouldn’t that way round make more sense?

Leave a Reply