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
306
Chapter 5
OK, I get it. In a GET request, the data is part of the
request URL, so it has to be just text. But in a POST
request, you can send an image, or XML, or plain text...
so we just need to tell the server what to expect.
You can send a lot more than plain text in a POST
request... as you’ll nd out in the next chapter.
But when a server receives your POST request, it
doesn’t know what kind of data it’s dealing with,
unless you tell the server what to expect.
Once the server knows what kind of data you’re
sending, it can decode the POST data, and handle
it properly. In the Break Neck app, that means
passing on the text for the address and order to
placeOrder.php... and making sure customers
are getting their pizza once again.
You need to set the content type
Servers get information from the
browser using request headers.
Web Browser
Internet Explorer
Firefox
Opera
Safari
Mozilla
<script>
var request...
function foo()
{
...
}
</script>
request.setRequestHeader(
“Content-Type”, “application/x-www-form-urlencoded”)
request headers
Hypertext Transfer Protocol
POST /placeOrder.php HTTP/1.1
Request Method: POST
Request URI: /placeOrder.php
Request Version: HTTP/1.1
Host: www.headrstlabs.com
Keep-Alive: 300
Connection: keep-alive
Content-Type:
application/x-www-form-urlencoded
Content-Length: 121
Here’s the request your
JavaScript sends to the server.
This is the request header
you added to the ...
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