JavaScript AJAX Basics (retiring) jQuery and AJAX Introducing jQuery

Maxim Melnic
Maxim Melnic
4,177 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,177 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,263 Points

Hey Maxim,

Are you executing the sendAJAX function?

sendAJAX();