How can you make a GET request through javascript and get a response from it (html code of a certain page)?
For example: site.ru/index.php site.ru/auth.php
You need to add a script to js in index.php so that it makes a get request to auth.php, and gets its source code.
I do this:
& lt; script type = "text / javascript" & gt;
var x = new XMLHttpRequest ();
x.open ("GET", "http://ya.ru/r=" + Math.random (), true);
x.onreadystatechange = function () alert (x.responseText);}
x.send (null);
& lt; / script & gt;
Answer 1, authority 100%
In pure JS, everything will work out. You have a typo: missed the “{“. And you need to catch the load
event instead of onreadystatechange
:
var x = new XMLHttpRequest ();
x.open ("GET", "/ echo / json /", true);
x.onload = function () {
alert (x.responseText);
}
x.send (null);