JavaScript AJAX Basics (retiring) AJAX Concepts A Simple AJAX Example

Chris George
Chris George
10,740 Points

Nothing Happening and I'm not sure why

I've looked over my code several times and don't see where my mistake is. Nothing happens in my browser and nothing appears in the console.

Screenshot of Workspace:

https://w.trhou.se/r51lz7wkp2

2 Answers

Jojo Menzies
Jojo Menzies
13,245 Points

you have a curly closing bracket on line 16. That's supposed to be the closing bracket for the conditional statement. Means it should be removed and inserted on line 13.

I forked your snapshot and moved the bracket to line 13 and it worked.

Chris George
Chris George
10,740 Points

Figured it out after completely deleting it and starting from scratch! Sometimes starting at code for hours makes you miss obvious mistakes and starting fresh clears your mind! Thanks for the reply :)

Chris Shaw
Chris Shaw
26,626 Points

Hi Chris George,

You should be at least getting an error as your script tag needs to be just before your closing </body> tag. The reason for this is the #ajax element doesn't exist at the time of the XHR request running.

Switching the placement of this code will result in it working.

Hope that helps.