AJAX JSON pure js

by Kishore Sahasranaman

JavaScript

You need to use [JSON.parse()][1] for deserializing the json response string. 

**See the below example:**

<!-- begin snippet: js hide: false -->

<!-- language: lang-js -->

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', 'http://ip-api.com/json', true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if(xmlhttp.status == 200) {
                var obj = JSON.parse(xmlhttp.responseText);
               document.body.innerHTML = "Your current location is " + obj.city;
             }
        }
    };
    xmlhttp.send(null);

<!-- end snippet -->


  [1]: http://www.w3schools.com/json/json_eval.asp