Prev | Current Page 61 | Next

Larry Ullman

"Building a Web Site with Ajax: Visual QuickProject Guide"

open(???post??™, ???add_employee_xml.php??™);
ajax.onreadystatechange = function() {
handleResponse(ajax);
}
64 adding records via Ajax
prepare the form data
1 The fi elds variable is an array of the form elements whose values
need to be sent to the PHP page.
2 Loop through each element in the array.
3 In the loop, each array element will be turned into a string in the format
name=value. So the fi rst array element, first_name, will be turned
into something like first_name=Larry. (See extra bits on page 83.)
4 In the loop, each form element??™s value is retrieved using
the Document Object Model. The value is run through the
encodeURIComponent() function for security purposes.
5 Outside of the loop, all of the array elements (the name=value pairs)
are joined together with ampersands. The end result is a string like
first_name=Larry&last_name=Ullman&??¦
6 The Content-Type header indicates what kind of information is
about to be sent. The value application/x-www-form-urlencoded
means that the content is encoded form data.
??¦
handleResponse(ajax);
}
var fields = [???first_name??™, ???last_name??™, ???email??™,
???department_id??™,???phone_ext??™];
for (var i = 0; i < fields.


Pages:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73