Categories
JavaScript Answers

How to replace HTML page with contents retrieved via Ajax with JavaScript?

Spread the love

Sometimes, we want to replace HTML page with contents retrieved via Ajax with JavaScript.

In this article, we’ll look at how to replace HTML page with contents retrieved via Ajax with JavaScript.

How to replace HTML page with contents retrieved via Ajax with JavaScript?

To replace HTML page with contents retrieved via Ajax with JavaScript, we set the Ajax response to document.body.innerHTML.

For instance, we write

<html>
  <body>
    blablabla
    <script type="text/javascript">
      document.body.innerHTML = "hi!";
    </script>
  </body>
</html>

to set 'hi!' as the value of document.body.innerHTML to update it.

Conclusion

To replace HTML page with contents retrieved via Ajax with JavaScript, we set the Ajax response to document.body.innerHTML.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *