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 trialJeremy Castanza
12,081 PointsXHR Objects not logging from button click event in Google Developer Console. Logging is on. Why won't it log?
I have the Google Developer tools console open. When using Google maps or something else along those lines, the console will log
XHR finished loading: GET "some URI"
However with this project, when using a button with the onclick attribute or the addEventListener method, there is no XHR reference in the console log... However, the AJAX response still comes through - as witnessed by the page change.
Any thought or explanation why the onclick event on the button wouldn't generate a console log entry even with the "Log XHRHttpRequests" option turned on?
Thanks!
1 Answer
Joel Kraft
Treehouse Guest TeacherHi Jeremy Castanza,
That is odd behavior. Here are a few questions to consider
- Which project file do you have open? (It sounds like example2.html.)
- Is the file being delivered to Chrome by a server? (If you are using Workspaces, then yes. If you are opening the file from a folder on your computer, then no.)
- Have you made any changes to the file?
- Are you getting any errors at all?
- Is caching disabled in DevTools? (Check the "Disable cache" in the "Network" tab.)
- Can you confirm the code in the page is in fact making an xhr request? The relevant code for this would be
xhr.send();
. If that code is present, but you're not sure if that line is executing, you can write aconsole.log()
right above and below that line, and then make sure you see those messages log out when you think they should. Something like:
console.log('before xhr request');
xhr.send();
console.log('after xhr request');
If you're not seeing these logs, or any errors, you might want to verify the right file is really loading. You can do this in the Chrome DevTools window, by clicking the "Network" tab, then selecting the file from the list on the bottom left (you may need to refresh the browser to see this list appear). Once you select the file, you should see some tabs appear to the right, and you want to select "Preview". Scroll through the file here and make sure it's the right code.
Let us know if this helps you figure out what is going on. If not, let us know what happened with these questions, and pasting in the code you're loading could help, too. Thanks!
Jeremy Castanza
12,081 PointsJeremy Castanza
12,081 PointsHi Joel,
I came up with a work around. I just cut and pasted the code from one of the example files into the index file. This seemed to fix the issue.
P.S. I was using Workspaces.
Thanks, Jeremy