0

I have simple XMLHttpRequest.

  var xhr = new XMLHttpRequest();
  xhr.open("GET", url, true);

  xhr.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
      console.log(this.responseText);
    }
  };

  xhr.send();

As you can see that I'm printing this.responseText in the console which outputs something like following

({ "status": "success", "data": { "title": "Post1" })

How can I get the JSON inside. I am totally aware of JSONP concepts but I don't want $.ajax in jQuery, I'm trying to achieve this via javascript. Thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612
Mani
  • 2,391
  • 5
  • 37
  • 81
  • You need a `callback=functionname` query parameter in the URL. – Barmar May 25 '22 at 23:58
  • And you don't use `XMLHttpRequest` for JSONP. The whole point of JSONP is that you use it for cross-domain requests, which won't work with AJAX. – Barmar May 25 '22 at 23:58

0 Answers0