(^178) ❘ CHAPTER 7 AJAX
though, because web-based applications are often supported with advertisements that make
them free.
Then another advantage still is that you can make a web-based application available to many more
operating systems and browsers than you might have otherwise with a self-contained desktop
application. You can target Safari, Chrome, Firefox, Internet Explorer, and Opera and reach more
than 99 percent of your browsing audience easily. Frameworks like jQuery make this even easier
because they eliminate many browser inconsistencies and headaches that might otherwise present as
roadblocks to cross-browser development.
There are some disadvantages to web-based applications, though, and a fair discussion should
include them. Because a web-based application can change so easily, some users will complain, and
some might even refuse to adapt. In addition, the speed of a web-based application has not come
close to the same speed offered by native programming. Speed is an issue because JavaScript is an
interpreted language, even with most browsers rapidly converting JavaScript to machine code and
caching it, which is a huge speed increase. JavaScript (along with (X)HTML and CSS) still has
network latency as an issue and still has a disadvantage in being an interpreted language that is
processed on-the-fl y instead of compiled like most of the desktop applications you use every day.
On mobile, the speed issue is still enough of a problem to keep most development from web-based
languages and browsers; instead most mobile development is done with a native compiled language
such as Objective-C, Swift, Java, or .NET. Finally, as a web-based technology, network or server
issues can potentially completely shut down user access to your application, although in some
development scenarios a network outage can be worked around.
Nonetheless, AJAX has become a powerful and increasingly essential component of web devel-
opment; this chapter covers jQuery’s built-in methods for making AJAX requests. As you would
expect, jQuery takes something that is moderately verbose and complex and boils it down into a
much simpler, easier-to-grasp API so that you can start writing AJAX-capable web applications
much more quickly.
Making a Server Request
As you’re probably already aware, the web works through a protocol called HTTP. When
you navigate to a web page, your browser fi res off a request to a remote HTTP server that’s
running Apache, nginx, Microsoft IIS, or some other HTTP server software, using the
HTTP communication protocol. AJAX makes it so that you can fi re off those HTTP requests
programmatically without having to reload the entire web page. After your JavaScript makes a
request and receives a response, you can then take that data and manipulate the content that’s in
front of the user based on the response that you receive. Using the HTTP protocol, there are many
ways that you can request data from the server. The most common ways information is transmit-
ted between an HTTP server and client are the GET and POST methods, although there are many
more methods that can be implemented as part of a RESTful service. If your server or application is
confi gured to support RESTful calls, you will also have methods such as PUT and DELETE, which
I discuss in the section “Sending a REST Request.” Before taking a look at REST, you should fi rst
be familiar with the most common methods of transmitting an HTTP request using a simple GET
or POST request.