Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,900 courses, including more Developer and personalized recommendations.Start Your Free Trial Now
- View Offline
- What is AJAX?
- Making requests asynchronous
- Updating the DOM with getElementById
- Reading JSON files
- Working with jQuery and AJAX
- Sending and searching JSON data
- Incorporating CSS transitions
Skill Level Intermediate
Although usage of early versions of Internet Explorer have dropped dramatically in the last few years, it's still important to know how to run AJAX requests that are compatible with those systems. And actually, the whole concept behind XHR requests was created by Microsoft and implemented first in a browser in IE5. To accomplish this, Microsoft used a technology called ActiveX. Because ActiveX was not available to other browsers like Safari, Firefox, and Chrome, they created a different implementation of the API using the XMLHttpRequest object.
Since ActiveX was seen as a proprietary implementation, the XMLHttpRequest object became the standard. So like with a lot of other web technologies, we've ended up with a fragmented implementation when trying to support older browsers. Luckily, all we have to do to support these browsers is to check if the browser API has an XHR object. So first, I'm going to change this line right here to just create the variable. Now I'm going to use an if statement.
So if the browser's API has the XMLHttpRequest object, then I'm going to set the request variable to this new object; otherwise, we'll check for the ActiveX object. The rest of our code is not going to change and our AJAX code should execute in the same manner. just refresh the page. You see that the page looks exactly the same, but my code is now more compatible with older browsers.
So even though you might not run into a situation in which you have to support really old browsers, it's good to know that doing it takes just a few lines of code.