Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Douglas Watts
5,464 PointsNo Popup
in this code when i run it in Workspace, it's supposed to create an alert.....because the 'missing.html' page doesn't exist:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=varela+round' rel='stylesheet' type='text/css'>
<link rel="stytlesheet" href="css/main.css">
<title>AJAX with Javascript</title>
<script>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
if(xhr.status === 200) {
document.getElementById('ajax').innerHTML = xhr.responseText;
} else {
alert(xhr.statusText);
}
}
};
xhr.open('GET','missing.html');
function sendAJAX() {
xhr.send();
document.getElementById('load').style.display = "none";
}
</script>
</head>
<body>
<div class="grid-container centered">
<div class="grid-100">
<div class="contained">
<div class="grid-100">
<div class="heading">
<h1>Bring on the AJAX</h1>
<button id="load" onclick="sendAJAX()">Bring it!</button>
</div>
<ul id="ajax">
</ul>
</div>
</div>
</div>
</div>
</body>
</html>
please help!
3 Answers
Dave McFarland
Treehouse TeacherThanks for pointing this out. What's happening is that when you preview a workspace and you request a file that doesn't exist, the server returns the index.html file. In other words the workspace server NEVER returns a 404 error. This is an unusual behavior that you won't find in most web servers. I believe we will be changing this back to the normal server behavior -- that is, the workspace preview will return a 404 when you request a file that's not found. Stay tuned.
Eric Martz
16,007 PointsI noticed in the Network section of Dev Tools that no matter what file name I put in I kept getting a 200 status code. Thought I was going crazy.
Dave McFarland
Treehouse TeacherSorry for the confusion Eric Martz
You are NOT going crazy :)
Douglas Watts
5,464 PointsEric,
here is the link: http://teamtreehouse.com/library/ajax-basics/programming-ajax/ajax-callbacks - it's at about 5:00 minutes in when he is setting up the alert.
Douglas Watts
5,464 PointsO.K.,
thanks to both for the effort!
Eric Martz
16,007 PointsEric Martz
16,007 PointsDoug,
Can you post which video were you trying to follow?
Thanks, Eric