Es gibt ein Problem, wenn ich versuche, eine JSON-Datei in einer Console (Chrome-Entwickler-Tools) zu sehen, es sagt Uncaught Typ Fehler request.onload ist keine Funktion, aber ich kann nicht finden, wo das Problem ist onload()
jemand helfen kann dank advaceUncaught TypeError: request.onload ist keine Funktion
<html>
<head>
<title>ajax php</title>
<!--<link rel="stylesheet" href="css/style.css">-->
</head>
<body>
<header>
<h1> json and ajax</h1>
<button id="btn">fet info from JSON file</button>
</header>
<div id="animal-info"></div>
<script src="main.js"></script>
</body>
</html>
<!--this code is in a seperate file main,js-->
enter code here
var request = new XMLHttpRequest();
request.open('GET', 'https://learnwebcode.github.io/json-example/animals-1.json');
request.onload() = function() {
var data = request.responseText;
console.log(request.responseText);
};
request.send();
Vielleicht finden Sie [diese Antwort] (http://stackoverflow.com/questions/9181090/is-onload-equal-to-readystate-4-in-xmlhttprequest#answer-9181508) hilfreich. – Utkanos