My files are located in the C:/xampp/htdocs directory.
I am trying to call:
{"name":"john", "age":19.4}
file from:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function ajax_json() {
var hr = new XMLHttpRequest();
hr.open("GET", "jsp.js", true);
hr.setRequestHeader("Content-type", "application/json", true);
hr.onreadystatechange = function () {
if (hr.readyState == 4 && hr.status == 200) {
var data = JSON.parse(hr.responseText);
var results = document.getElementById("results");
results.innerHtml = data.name;
}
}
hr.send(null);
results.innerHTML = "requesting...";
}
</script>
</head>
<body>
<div id="results"></div>
<script type="text/javascript">ajax_json();</script>
</body>
</html>
file.
When I click on the HTML file, it just writes "requesting..." but does not call the AJAX. I have double-checked my codes multiple times as I followed a tutorial and others who watched the same tutorial were able to achieve it. Where could I be going wrong each time? Should I save my files somewhere else or with different extensions (.html, .js)?