Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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'.