Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Implement a Callback

XMLHttpRequest object event handlers

Having just finished AJAX basics and moving into this course I got very confused about the function written in this code to create the XMLHttpRequest object. It took me a while to realize what was so confusing, but I figured out that there is a method called on the XMLHttpObject that is not used in the AJAX basics course, xhr.onload. It seems this method is actually an event handler that has been recently added by various browsers? Furthermore, when I went back to the AJAX course I recalled we were told there were 4 steps to creating an AJAX request - 1. create the object, 2. write the callback, 3. open the request, 4. send the request. This code does not create the callback until after opening the request, yet another confusing point. I think it would be helpful if at a minimum a link is included in the teacher's notes to some content on this new method, .onload - as otherwise it is confusing. I found some info on mdm here - https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/onload - however it was not particularly informative. Perhaps you have access to something better?

I second everything that has been said by Heather Cloward. I'm really struggling due to the lack of information regarding these new/not familiar methods.

1 Answer