Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1
Lesson 1: Understanding forms CHAPTER 7 323

An advantage of using the GET verb is that you can see and modify the complete URL
and QueryString in the address bar of the web browser as needed. However, depending on
the scenario, this could also be a disadvantage. The complete URL and QueryString are easy
to save or send as a unit. For example, you can bookmark a webpage containing data that is
included in the QueryString.
One disadvantage of using the GET method is that the QueryString is limited in size by the
web browser and web server you use. For example, when using Internet Explorer and Internet
Information Server (IIS), the limit is 1,024 characters. Another consideration is that you might
not want to allow a user to type the URL and QueryString directly into the address bar with-
out navigating through other webpages first.
When you use the POST method to submit data back to the web server, the data is placed
in the message body instead of being concatenated to the URL. This makes the data invisible,
at least to the typical user. Using the POST method removes the size constraint on the data.
You could post megabytes of data; although it will work, sending that much data across the
Internet can cause other problems, primarily bandwidth-related, such as timeout errors and
performance problems.
The POST method does not allow the user just to type the data into the QueryString
because this data is hidden in the message body. For most scenarios, consider using the POST
method to send data to the web server.
Sending data back to the server is often referred to as a PostBack to the server when the
POST method is used.

Lesson summary


■■HTTP protocol is a text-based protocol that sends a method, or verb, to indicate the
type of request being made. Common methods are GET and POST. GET is typically
used to retrieve a resource; POST is typically used to update a resource.
■■Web servers reply to requests and send a three-digit status code in which 1xx is infor-
mation, 2xx is success, 3xx is redirect, 4xx is client error, and 5xx is server error.
■■Data can be submitted to the web server by adding a <form> element with form sub-
mission elements. Form submission elements are <textarea>, <select>, <input>, and
<button>.
■■Use a <button type=’submit’>, <input type=’submit’>, or <input type=’image’> to
submit a form.
■■The jQuery serialize function converts form data to a URI-encoded list of name-value
pairs.
■■The decodeURIComponent can be used to decode a QueryString.
■■The autofocus attribute sets the focus when the page is loaded.

Key
Te rms

Free download pdf