Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
26
Chapter 1
Initializing the connection
You’ve got a request object, and a variable with the URL to connect to.
Now you just need to tell the request object how to connect to the server,
and give it that URL as the address to connect to. Here’s how you do that:
Q:
I thought that it was better to use
“POST” for web page requests.
A: POST is usually used when you are
sending a server lots of data, or are completing
a form submit that involves money, or placing
an order. Since we’re not sending any data to
the PHP script, and there’s no purchase being
made here. it’s easier to use a GET request;
we’ll look at POST requests a little later on.
Q:
Should I ever use open() to make a
synchronous request, and set that last value
to “false”?
A: Sure. Sometimes you don’t want the user
to be able to keep using your page while the
server is answering a request. For instance, if
a user is placing an order, you probably don’t
want to let them do anything else until you
confirm that their order was accepted.
questions
Frequently asked
?
Let’s break that down a bit...
request.open(
“GET”,
url,
true);
The open()
method initializes
a connection...
...and then “GET” indicates how
to send data to the server.
This is the URL for the
PHP script running on
Katie’s web server.
This means that the request should
be asynchronous... in other words,
this lets JavaScript know that it
doesn’t need to wait around for a
resp
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content