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 trialJoshua Ouma
20,865 PointsWhy doesn't my button work?
I have followed the steps in the video correctly, yet my button still doesn't work as expected. why?
Joshua Ouma
20,865 Points <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href='//fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/main.css">
<title>AJAX with JavaScript</title>
<script>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
document.getElementById("ajax").innerHTML = xhr.responseText;
}
};
xhr.open("GET", "sidebar.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" onlick="sendAJAX();">Bring it!</button>
</div>
<div id="ajax">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Joshua Ouma
20,865 PointsI have included my code
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsHave you created a separate file called sidebar.html ?
Joshua Ouma
20,865 PointsYes, I have included everything. Actually it works perfectly without the button. But when I add the button, clicking the button doesn't display the expected text
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsAre you sure you're using workspaces? As I just copied your code into workspaces and it works fine?
Joshua Ouma
20,865 PointsYes
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsCan you take a snapshot of your workspace? You can do this by clicking the camera button on the top right of your workspace. Once done, copy and paste the link of the snapshot here so I can see
Nelson J
7,411 PointsI am having the same problem
2 Answers
Kevin Gates
15,053 PointsYou put onlick()
instead of onclick()
. You're missing the "c" in "click".
horacinis
4,824 Points<button id="load" onlick="sendAJAX();">
Yeah, you put "onlick" instead of "onclick" but I see another mistake, you put a semicolon at the end of "sendAJAX();", remove that semicolon so it its "sendAJAX()", without the semicolon.
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsDaniel Turato
Java Web Development Techdegree Graduate 30,124 PointsCould you you copy your code here so I can help with your problem