0 points

Vanilla Javascript - How to make an AJAX call without jQuery?


dashboard

Mon May 11 2020 22:17:10 GMT+0000 (UTC)

Posted by @mishka #javascript

<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>
content_copy Copy

https://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery