<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
// Call this function when the AJAX returned information
function MyFunction()
{
alert("AJAX returned value");
}
// AJAX call
function call_ajax(divId,functionto_call)
{
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
// insert responseText into divID object
document.getElementById(divId).innerHTML = this.responseText;
// Call function when AJAX info arrived
functionto_call();
}
};
xhttp.open("GET", "file.txt", true); // The file must exist
// xhttp.open("GET", "get_list.php?id="+MyID, true); // Call with parameter read using $_REQUEST[]
xhttp.send();
}
</script>
<title>AJAX Call</title>
</head>
<body>
<div id="show"></div>
<script>
call_ajax("show",MyFunction);
</script>
</body>
</html>