XHR issue in a local file

var request = new XMLHttpRequest();
request.open('GET', 'data.txt');
request.onReadyStateChange = function() {
	if (request.status===200) {
		console.log(request);
		document.writeln(request.responseText);
	}	
}	
request.send();

index.html →


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>JavaScript AJAX</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

But nothing is outputting →

Hi @codeispoetry, you can get more details about the request (status code etc.) in the network tab of the browser dev tools (should be somewhere next to Console and Sources).

1 Like

Hi @m3g4p0p

All seems good →

Ah, onreadystatechange is written all lower case.

1 Like

Thanks sir, it worked.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.