Lucas Randisi Lucas Randisi - 3 months ago 14
Javascript Question

Retrieving data from an external site

I would like to get some values from an external site that is loaded using js functions. Until now i have tried something like i this but im sure is not the correct way

window.location = "http://dashboard.monitis.com/sharedPage.jsp?tI=OHIHg3S9XiBj70SNtIGi0g%253D%253D&uI=hGCXtzJFZF0M2GGYsvfYunNBx3EZykTidEFveqU24IY%253D";


x = document.getElementsByClassName('x-grid3-cell-inner x-grid3-col-1')[0].textContent;

alert(x);

Answer

window.location will redirect your browser to that location, so the rest of your script is never executed. You probably want to fetch the contents of that url using an ajax request and then do something with that content.

xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    console.log(this.responseText);
  }
};
xhttp.open("GET", "http://dashboard.monitis.com/sharedPage.jsp?bla..bla", true);
xhttp.send();