Skip to Main Content
Adding Ajax
book

Adding Ajax

by Shelley Powers
June 2007
Intermediate to advanced content levelIntermediate to advanced
400 pages
9h 52m
English
O'Reilly Media, Inc.
Content preview from Adding Ajax

Ajax Libraries: Homegrown or Borrowed

Most of the examples in the book don't use libraries other than the Adding Ajax library, addingajax.js, which we "growed up" as we went along. This leads to another major decision when beginning Ajax development—whether to create your own Ajax library, or use one or more of the many free libraries available on the Internet.

Some libraries such as Prototype provide basic functionality and are quite small. Others, though, can be rather large, and unless you have a real commitment to integrate them into your application, the bandwidth needed for the library isn't justified.

You can mix libraries as long as each uses some form of namespacing to prevent conflicts, and as long as the libraries are using event handlers that don't tromp all over each other or your own code, of course.

As for creating your own library, you can take a minimal, basic library such as addingajax.js and add your own components. One such addition is simplified processes to add and access DOM elements in order to cut down on the amount of code. The following example creates a two-item unordered list, with each item containing an anchor element:

// create unordered list container var ul = document.createElement('ul'); // create two anchor elements var a1 = document.createElement('a'); var a2 = document.createElement('a'); a1.setAttribute('href','http://someurl.com/'); var txt1 = document.createElement('some text'); a1.appendChild(txt1); a2.setAttribute('href','http://someotherurl.com/'); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ajax: The Definitive Guide

Ajax: The Definitive Guide

Anthony T. Holdener III
Ajax Design Patterns

Ajax Design Patterns

Michael Mahemoff
Web Development with JavaScript and Ajax Illuminated

Web Development with JavaScript and Ajax Illuminated

Richard Allen, Kai Qian, Lixin Tao, Xiang Fu

Publisher Resources

ISBN: 9780596529369Supplemental ContentErrata Page