04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

form methods: get and post<br />

POST<br />

GET<br />

620 Chapter 14<br />

Now that we’ve got the form<br />

finished, can we talk about the method<br />

the browser uses to send this data to the<br />

server? We’ve been using “POST”, but<br />

you said there are other methods, too.<br />

There are two primary methods<br />

the browser uses: POST and GET.<br />

POST and GET accomplish the same thing – getting<br />

your form data from the browser to a server – but<br />

in two different ways. POST packages up your form<br />

variables and sends them behind the scenes to your<br />

server, while GET also packages up your form variables,<br />

but appends them on the end of the URL before it<br />

sends a request to the server.<br />

firstname=buck<br />

lastname=bonz<br />

item=java<br />

number=2<br />

http://www.headfirstlabs.com/contest.php<br />

The request doesn’t<br />

have any of the form<br />

data in it.<br />

With POST all the form data is sent as part of<br />

the request and is invisible to the user.<br />

Web<br />

Application<br />

With GET, the form data is added to the URL<br />

itself, so the user sees the form data.<br />

Web<br />

Application<br />

http://www.headfirstlabs.com/contest.php?firstname=buckaroo&lastname=banzai<br />

The user just<br />

sees the Web<br />

application’s URL<br />

in her browser<br />

address bar.<br />

Notice the form<br />

data added on<br />

to the end of<br />

the URL. This<br />

is what the<br />

user sees in the<br />

address bar.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!