Working with XHR: response.
Tue Apr 22 2025 18:27:32 GMT+0000 (Coordinated Universal Time)
Saved by
@fsd
<!DOCTYPE html>
<html>
<head>
<title>XHR Test</title>
</head>
<body>
<script>
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts/1', true);
xhr.onload = function () {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
console.log("Response Data:", data); // This should show the post object
// Optional: shows a popup so you know it worked
} else {
console.error("Error: " + xhr.status);
}
};
xhr.onerror = function () {
console.error("Network error");
};
xhr.send();
</script>
</body>
</html>
content_copyCOPY
Comments