Prev | Current Page 62 | Next

Larry Ullman

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

length; i++) {
fields[i] = fields[i] + ???=??™ +
encodeURIComponent(document.getElementById(fields[i]).
value);
}
var values = fields.join(???&??™);
ajax.setRequestHeader(???Content-Type??™, ???application/xwww-
form-urlencoded??™);
adding records via Ajax 65
complete the function
1 After all the data handling, the actual
Ajax request is made. The form data, represented
by the variable values, is used as
the only argument to the send() method.
(See extra bits on page 83.)
2 Finally, the function returns a value of false to
tell the Web browser not to actually submit the form
(since Ajax is handling the form submission).
Save this fi le as add_employee.js
and place it in the same directory on
your Web server as every other fi le.
??¦
ajax.setRequestHeader(???Content-Type??™,
???application/x-www-form-urlencoded??™);
ajax.send(values);
return false;
} // End of anonymous function.
} // End of DOM check.
} // End of ajax IF.
} // End of init() function.
66 adding records via Ajax
prepare for XML
A new PHP script will do the same thing as add_employee.php, only it will
return all of its results as XML data.


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