0
$.ajax({
  url: 'https://www.gravatar.com/avatar/71b0d516013802a2d67aeb7c2e77ed32?s=48&d=identicon&r=PG&f=1',
  success: function(r, s, x){ 
    var type = x.getResponseHeader("content-type");
    console.log(type); 
  }
});

This is the ajax requesti written to get the type of image .How can i do the same with pure javascript?

silpa jacob
  • 76
  • 11

1 Answers1

1

With JavaScript you need to do something like this ::

<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>
Hardik Kalathiya
  • 2,221
  • 1
  • 18
  • 28