A quick check to be sure the
user entered all the required information, and then it is just a matter of an Ajax call to the
AddressBookManager??™s saveContact() method, passing the appropriate arguments along. The
server will respond with a success or failure message, so all the response handler has to do is
display what was returned. This is akin to doing a System.out.println on the return from a
method on the server, since saveContact() returns a plain old string. One problem I encountered
is that there is sometimes a slight delay before the Address Book file is actually written to
disk (this is also true when deleting a contact). Because of this, the returned message informs
users that they may have to click the Address Book link to see the new contact.
To go along with saveContact() is deleteContact():
// Called to delete a contact.
function deleteContact() {
contactName = getValue("contactNameEntry");
if (contactName == "") {
alert("Please select a contact to delete");
hidePleaseWait();
return false;
}
showPleaseWait();
AddressBookManager.deleteContact(contactName, replyDeleteContact);
}
// Our callback.
var replyDeleteContact = function(data) {
newContact();
alert(data);
hidePleaseWait();
gotoAddressBook();
}
Very much like saveContact(), deleteContact() checks for the required information, and
then makes an Ajax call to perform the delete.
Pages:
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312