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 AJAX Basics (retiring) jQuery and AJAX Introducing jQuery

Maxim Melnic
Maxim Melnic
4,178 Points

Fetch don't work(

Hi, I want to try this example to apply with Fetch API, but it does not work. What's the problem?

function sendAJAX() {
    fetch("./sidebar.html")
      .then(response => console.log(response))
      .then(response => $("#ajax").html(response.responseText));
    };

2 Answers

Maxim Melnic
Maxim Melnic
4,178 Points

.responseText don't work with Fetch, need to use .text() method

function sendAJAX() {
      fetch("sidebar.html")
        .then(response => response.text())
        .then(data => $("#ajax").html(data));
    };
Jesus Mendoza
Jesus Mendoza
23,289 Points

Hey Maxim,

Are you executing the sendAJAX function?

sendAJAX();