Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <body> <div>post title: <span id="spanId"></span></div> <script> function httpGetAsync(theUrl, callback) { let xmlHttpReq = new XMLHttpRequest(); xmlHttpReq.onreadystatechange = function () { if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) callback(xmlHttpReq.responseText); }; xmlHttpReq.open("GET", theUrl, true); // true for asynchronous xmlHttpReq.send(null); } httpGetAsync("https://jsonplaceholder.typicode.com/posts/1", function (result) { document.getElementById("spanId").innerText = JSON.parse(result).title; }); </script> </body> </html>