# Making HTTP Requests in JavaScript | kirupa.com

**URL:** <https://forum.kirupa.com/t/making-http-requests-in-javascript-kirupa-com/633636>\
**Category:** programming\
**Created:** [August 21, 2015, 6:48am UTC](https://forum.kirupa.com/t/making-http-requests-in-javascript-kirupa-com/633636 "2015-08-21T06:48:53Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [April 2, 2018, 4:05pm UTC](https://forum.kirupa.com/t/making-http-requests-in-javascript-kirupa-com/633636/4 "2018-04-02T16:05:55Z")

</div>

@dagoeos The `response` property may be one of many different data types including, but not limited to a string. Using `responseText` makes it clear that you’re after the text version of the data, even though it will likely be the same value as `response` in this case.

That being said, a valid response type is “json” which is our target format for this data, so if we wanted to have that parsing happen automatically, we could set the `responseType`, skip `JSON.parse`, and pull directly from `xhr.response`.

```auto
var xhr = new XMLHttpRequest();
xhr.responseType = "json"; // xhr.response will be parsed into a JSON object
xhr.open('GET', "https://ipinfo.io/json", true);
xhr.send();
 
xhr.onreadystatechange = processRequest;
 
function processRequest(e) {
    if (xhr.readyState == 4 && xhr.status == 200) {
        alert(xhr.response.ip); // no parsing needed
    }
}

```

---

_[View the full topic](https://forum.kirupa.com/t/making-http-requests-in-javascript-kirupa-com/633636)._
