Files
IWD2-02/INFO-3168 (JS 2)/Notes/simple_ajax/sync_ajax.html
T
2026-01-22 22:24:56 -05:00

40 lines
815 B
HTML

<html>
<head>
<title>Synchronous AJAX</title>
</head>
<body onload="main();">
<script type="text/JavaScript">
function getJSONSynchronous(url){
let response = "";
let xmlHttp = new XMLHttpRequest();
if(xmlHttp !== null){
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
response = xmlHttp.responseText;
return response;
}
}
function writeToContent(data){
document.getElementById("content").innerText = data;
}
function main(){
writeToContent(getJSONSynchronous("https://google.ca"));
writeToContent(getJSONSynchronous("https://reqbin.com/echo/get/json"));
writeToContent(getJSONSynchronous("./data.json"));
}
</script>
<div id="content">
</div>
</body>
</html>