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 trialMicole Noddle
5,797 PointsIs AJAX always written in the HTML or is it written in the JavaScript file?
A couple of questions here...
1) Is AJAX actually written inside the HTML all the time or is it just something Dave is doing in the beginning of this course? (For example, in the beginning of the JavaScript course he showed us how to write JavaScript in the HTML even though it wasn't common practice). Is it common practice to write AJAX in the HTML? Or do we write AJAX in our JS file that we link to our HTML?
2) And why are we writing 4 in our readyState? There really isn't an explanation as to what different numbers mean....did I miss something here?
Also, is anyone else feeling as lost as I am? I feel like we went from 0 to 60 in the first 2 minutes of this video. This is my first experience with AJAX. After just coming off of the JQuery and Interactive Website courses (which I also found very confusing), I'm starting to get a little discouraged...
1 Answer
Liam Maclachlan
22,805 PointsHey there.
Totally agree. You feel completely side swiped with these videos on javascript and ajax. It's not the knidest language when you start it but you quickly learn its methods of how it works.
With AJAX it is totally fine to write it in either the HTML or the .JS file as long as you can access it :) I tend to have mine in the .JS file to keep my markup tidy.
4 in the readystate is needed as the AJAX has 4 stages. 4 is the final stage once the request is finished. Think of it as a listener for when your request has been answered by the server.
On a learning note...
I personally find it a good idea (one of the teachers actually recommends this) to:
1 - watch the video from start to finish 2 - watch it a second time and keep pausing and take notes 3 - watch it a third time to make sure you have a grasp of the concepts being taught.
Something I have noticed is that they focus on teaching you one thing per video and then use it in a bunch of different ways in that video.
Repetition is key!
P.S: I often find watching the videos in speed 1.25+ a much better way to overview the information.
Micole Noddle
5,797 PointsMicole Noddle
5,797 PointsThanks, Liam. I watch the video, then I watch it and I take copious notes, but with these classes I'm getting so frustrated I can't make it through watching a third time. Oh, and I just noticed the code in Workspaces doesn't even match the code Dave has up for this video. I do find it easier to use Workspaces for these courses, but it is also frustrating when they don't match!
So in the readystate are we always writing 4? Is there ever a need to write 0-3?
Do we end up writing as many lines of AJAX as we do JS and JQuery?
The initial JS courses were the best ones I've taken so far, but, I feel like the rest have taken an odd turn--not necessarily tailored for us newbies, more for those who are experienced. And I don't think those of us who are newbies are experienced just because we've completed more courses in the track. It actually gets harder because we're here trying to absorb so much new info all at once!
Liam Maclachlan
22,805 PointsLiam Maclachlan
22,805 PointsPersonally I have never used the workspaces. They are great for some but my style of learning needs me to go off on my own for a few days and make a ton of mistakes. It can be incredibly frustrating but it has definitely made me a much better coder.
ReadyState Value Description
0 = "uninitialized" state in which an XMLHttpRequest object has been created, but not initialized.
1 = Represents a "sent" state where the open() method is ready to send a request to the server.
2 = Represents a "sent" state in the send() method has triggered, but a response has not yet been received.
3 = Represents a "receiving" state in which responses have been received, but message has not yet been completely received.
4 = Represents a "loaded" state in which the response has been completely received.
(full version here http://www.devx.com/webdev/Article/33024/0/page/2)
The Ajax is only a few lines of code that interacts with the server, without having to reload the page.
It may be worth while starting on a less brutal learning curve as AJAX/javascript. Have you tried the front end developer tracks on here? They are really well constructed to make sure you don't dive in to something to soon. There are may videos on here I'm not even ready to look at and the tracks give me a good perspective on where I should probably go next.
I think when I started on here I would leave my treehouse account for weeks at a time and explore what I'd learned. I've been active on here for about 2/3 years and I have just landed my first full time, in house developer job.
Don't overload your self too much and just enjoy what is being taught. That is what will make a huge difference in overcoming a lot of the tougher lessons that can be taught on here :)
Micole Noddle
5,797 PointsMicole Noddle
5,797 PointsI like workspaces for some of the classes. Some I will do in a text editor in addition to workspaces, but these have been so difficult I haven't felt comfortable going off on my own yet.
I'm actually doing the front end developer track, this part is really difficult! I'm not trying to rush either, I've been at it for 2 months full-time and have just landed in this course. It's definitely a ton of info to absorb.
Thank you for the tips, advice and encouragement, I appreciate it! And congrats on the new job! :)
Liam Maclachlan
22,805 PointsLiam Maclachlan
22,805 PointsHaha. Thank you. Very nervous and excited right now. Keep up the good work and just enjoy yourself :)