Quiz
- In the Ajax graphic, the back-end code is written in Python. Are back-ends usually written in Python? Wouldn't that be slow?
Backends are written in Python, JavaScript, PHP, Ruby, Perl, and many other languages. Not usually very fast ones.
Python is slower than C for raw computation, but it's not that slow. Web applications are typically I/O bounds (limited by speed of I/O rather than speed of computation), so the speed of the programming language is usually unimportant.
- Just to clarify, jn the Adjustments to Truck part of the reading, the reason why the argument to this.db.get is because we're dealing with Ajax now and there needs to be a callback function?
Yes, that's exactly right. Well done!
- What does it mean for a method to be a wrapper?
Great question. Let's start with functions. Suppose I have a function that computes square roots, but it breaks if the argument is negative. I could do this:
We would call
sqrt
a wrapper aroundrealSqrt
.Methods work the same way:
- Can you further explain why $.get() method is called a wrapper for $.post()?
I think you mis-read that. Both
$.get
and$.post
are wrappers around$.ajax
- could you explain .get(), .post(), and .ajax()? and when you would use each one
Sure. This is based on MDN HTTP Methods and (simpler and easier) W3Schools HTTP Methods
- use GET when retrieving information from the server (e.g. browsing Instagram)
- use POST when updating information on the server (e.g. POSTing to Instagram)
- use AJAX when neither of the above, such as DELETE.
- how are errors handled when using callback functions in ajax?
Great question! Let's briefly look at the jQuery documentation
- How can we test if our ajax code is working? I tried the codes in my console but i kept getting some values undefined even though i inserted some url and some objects.
Wonderful question! Thanks so much for trying these. I'll demo some stuff in CoffeeRun:
And, in the CS 304 Ajax movie rating app:
- There is nothing more I would like to talk about. / Everything is clear
Great!