40 lines
815 B
HTML
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> |