Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (6.1k points)

Can we do it using Javascript to make Ajax call?

1 Answer

0 votes
by (11.7k points)

We can achieve this by using Vanilla script as follows:

<script type="text/javascript">

function loadXMLDoc() {

    var xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function() {

        if (xmlhttp.readyState == XMLHttpRequest.DONE) {   // XMLHttpRequest.DONE == 4

           if (xmlhttp.status == 200) {

               document.getElementById("myDiv").innerHTML = xmlhttp.responseText;

           }

           else if (xmlhttp.status == 400) {

              alert('There was an error 400');

           }

           else {

               alert('something else other than 200 was returned');

           }

        }

    };

    xmlhttp.open("GET", "ajax_info.txt", true);

    xmlhttp.send();

}

</script>

If you want to become an expert in web development and tackle this kind of problem, you can check out the web development course offered by Intellipaat.

Browse Categories

...