HTML and CSS Reference
In-Depth Information
message body in an HTTP header to the server. This POST data will not be visible in the
location box and is not limited in size so this method is normally used to send data from
a form. The server-side program (e.g., PHP, ASP.NET, CGI), will then process the data
and send back its response in a brand new page while the user waits. Example 18.12 is
a traditional HTML form.
A Traditional HTML Form
<head><title>An HTML Form</title></head>
<form ACTION="http://localhost/guestbook.php" METHOD="post"><p>
Your name:
<input type="text" name="username" size="50" /><br />
Your phone:
<input type="text" name="userphone" size=50/><br />
<input type="submit" value="Submit" />
When creating HTML forms with AJAX, the <form> tag will not be given an ACTION
or a METHOD attribute and the submit button will not be used to submit the form data.
Instead, an event handler will trigger off the chain of events that deal with the commu-
nication between the browser and server. Whether using GET or POST, because Ajax is
making server requests, the user will not have to wait for an entire page to be returned
before continuing to work on the page. The next examples will demonstrate how to cre-
ate and process forms with Ajax.
The GET Method. Example 18.13 demonstrates how to create an Ajax form using the
GET method. The example can be divided into four parts. First the program checks for
the type of browser being used and creates the Ajax request object. The second part cre-
ates the Ajax functions that will send a request to the server, check for the state of the
server, and when the server completes a request, will handle the data that comes back.
In the next part, the HTML form is created with a div container to hold the data that will
come back from the server. Finally the server-side PHP program on the server side
receives the form data from the server, handles it, and sends it back to the server. The
PHP program might be responsible for validating logins, sending database queries, read-
ing or writing to files, starting sessions, cookies, and so on.
Search WWH ::

Custom Search