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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.