16.4. Tying It All Together
Now that you know all about the architecture, database, user interface, and server-side components, it's time to glue it all together using JavaScript. To begin, you need to define some constants. The first constants are simply locations of various resources that need to be used by AjaxMail:
var sAjaxMailURL = "AjaxMailAction.php"; var sAjaxMailNavigateURL = "AjaxMailNavigate.php"; var sAjaxMailAttachmentURL = "AjaxMailAttachment.php"; var sAjaxMailSendURL = "AjaxMailSend.php"; var sImagesDir = "images/"; var sRestoreIcon = sImagesDir + "icon_restore.gif"; var sDeleteIcon = sImagesDir + "icon_delete.gif"; var sInfoIcon = sImagesDir + "icon_info.gif"; var sErrorIcon = sImagesDir + "icon_alert.gif"; var aPreloadImages = [sRestoreIcon, sDeleteIcon, sInfoIcon, sErrorIcon];
The first parts of this code simply define the URLs used to make requests back to the server. These will be used later to integrate the Ajax interface. The second part of this code identifies images that are necessary for the user interface and then places them into an array called aPreloadImages. These images are preloaded so that the user interface responds quickly:
for (var i=0; i < aPreloadImages.length; i++) { var oImg = new Image(); oImg.src = aPreloadImages[i]; }
This code uses an Image object, which is essentially an invisible <img/> element. Because not all of these images are necessary when the application is first loaded, most won't be loaded until used for the first time. ...
Get Professional Ajax, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.