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!

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 AJAX Basics (retiring) AJAX Concepts A Simple AJAX Example

Ogechi Ike
Ogechi Ike
6,539 Points

I can't get my ajax example to work.

I have checked the video and the mdn documentation of ajax, but the ajax event won't work. It keeps saying:

Uncaught TypeError: undefined is not a function(index):12 ajax.onreadystatechangeXMLHttpRequest.send (async)(index):16 (anonymous function)

Here is my code:

      var ajax = new XMLHttpRequest();//sets up a new AJAX object
      ajax.onreadystatechange = function(){
        if(ajax.readyState === 4){
            document.getElementByID('ajax').innerHTML = ajax.responseText;
    ajax.open('GET', 'sidebar.html');//GET is the HTTP Method that gets the information from the sidebar.html
    ajax.send();//send the information from sidebar.html back to the index

1 Answer

Erik Krieg
Erik Krieg
43,038 Points

Quickly looking through I noticed that you have capitalized the "d" in the method "getElementById"

That might fix your problem, but if not, lemme know! ♥

Ogechi Ike
Ogechi Ike
6,539 Points

Thanks, Erik. I ha already found my mistake. It was the capital 'D'.