Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Creating Web Pages With Ajax

Posted by samzenpus on Mon Oct 16, 2006 02:28 PM
from the if-you-build-them-they-will-come dept.
Ravi writes "Asynchronous Javascript And Xml, popularly known as Ajax, is a combination of Javascript, XML and some coding on the server side. Even though this technology existed for years, many believe it was Google which brought it to the front by implementing it on its sites and thus raising it to the cult status it enjoys now. There is something magical in seeing a website update its content without reloading the whole page, which is the visual essence of Ajax." Read the rest of Ravi's review.
AJAX - Creating Web Pages with Asynchronous JavaScript and XML
author Edmond Woychowsky
pages 390
publisher Prentice Hall
rating 9
reviewer Ravi
ISBN 0-13-227267-9
summary A useful introductory book in picking up the skills in using Ajax


I found the book titled "AJAX — Creating web pages with Asynchronous JavaScript and XML" authored by Edmond Woychowsky to be a very good introductory level book on learning the basics of Ajax. Spanning 390 pages and 16 chapters, this book imparts a sound understanding of the basic features which make ajax possible.

The author starts by giving a brief introduction to the different types of web pages — static and dynamic, the tools and code used to serve them.

In the second chapter which is titled "Introducing Ajax", the author dives into the philosophy and principles of Ajax and with the aid of three simple examples explains three different ways of implementing ajax in a webpage. I found this chapter to clear some of the doubts that a newbie will have about the hype surrounding ajax.

The third chapter takes a step backwards in that it gives a birds eye view of all the XHTML elements and their associated attributes. The author also provides a table which lists the most commonly used CSS 1 elements. I found this chapter more of a ready reference than an indepth thesis on XHTML and CSS.

The fourth chapter titled "Javascript" provides a very good understanding of the language. Javascript plays an invaluable part in the greater scheme of the working of Ajax. Apart from the snippets of code and explanations, this chapter also has a number of tables listing things such as the essential JavaScript functions, characters used to create regular expressions, event handlers, Javascript operators and so on.

In the next chapter titled "Ajax Using HTML and JavaScript", the author explains how to use HTML, Javascript and stored procedures incorporated in the latest version of MySQL to create a semblance of an Ajax shopping cart. What is worth noting is that this chapter explains an old fashioned but very reliable technique which uses hidden frames and inline frames to update the data on the page. Of course the author is quick to point out that this technique is not really Ajax in the sense that it lacks the XML part.

I found the author's narration quite refreshing as he explains each concept one at a time with the aid of snippets of code, gradually building up and eventually tying all the threads together to write a true Ajax web application.

XML — eXtensible Markup Language is the successor of SGML — the language which powers HTML. XHTML on the other hand uses the XML schema. XML is a vast subject which can easily fit in a book of its own. Perhaps knowing this, and because XML plays a significant part in Ajax, the author has intelligently provided just the necessary information about XML in the sixth chapter.

The seventh chapter is a very important chapter which gives an indepth understanding of the XMLHttpRequest object which can be considered the brain behind Ajax. The author also provides some insights into the XML document object model, RSS and Web services such as SOAP.

In Chapter 8, the author gives a more indepth take on the XMLHttpRequest object and the other technologies explained in the previous chapter and illustrates by applying them in building a shopping cart application. Throughout the book, the author has highlighted the fact that ajax is a browser dependent technology and if people disable javascript in their browsers, then the whole effort will come to naught.

XPath is a technology which can be used to locate and navigate the various parts of an XML. The ninth chapter gives an introduction to the syntax used by XPath.

The next two chapters explain the concept of eXtensible Stylesheet Language for Transformations (XSLT) and how it can be used to implement Ajax. XSLT can be compared in some ways to CSS but is much more powerful and can be used to display pure XML in different styles targeting diverse media. These two chapters contain all the necessary details such as the syntatic reference and snippets of code which walks one through creating an Ajax application using XSLT.

In chapter 12, the author talks about the advantages of code reuse where creating javascript objects are explained. Surprisingly, there are two chapters on Ruby on Rails — the latest fad with the web developer community.

I found the book to be a valuable reference for upcoming Ajax web programmers. The number of tables listing the tags and their attributes itself will more than make up for the cost of the book. It has the right amount of content covering all pertinent topics without overwhelming the reader, which makes it a very good introductory book on Ajax.

Ravi Kumar is passionate about all things related to open source and free software and likes to share his thoughts and experiences related to these through his site "All about Linux".


You can purchase AJAX - Creating Web Pages with Asynchronous JavaScript and XML from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • Like frames, eh? (Score:3, Insightful)

    by xxxJonBoyxxx (565205) on Monday October 16 2006, @02:41PM (#16457315)
    There is something magical in seeing a website update its content without reloading the whole page
    Like frames, eh? (Or Java, Flash, older Javascript apps, etc. etc. etc.)
    • Like regular applications, eh? by iamacat (Score:2) Monday October 16 2006, @03:28PM
      • Re:Like regular applications, eh? by suparjerk (Score:1) Monday October 16 2006, @03:40PM
        • Re:Like regular applications, eh? by iamacat (Score:2) Monday October 16 2006, @04:41PM
          • Re:Like regular applications, eh? by GnuDiff (Score:1) Monday October 16 2006, @04:49PM
            • Re:Like regular applications, eh? by iamacat (Score:2) Monday October 16 2006, @04:55PM
              • Re:Like regular applications, eh? by myz24 (Score:2) Monday October 16 2006, @06:11PM
              • Re:Like regular applications, eh? (Score:4, Insightful)

                by Sancho (17056) on Monday October 16 2006, @06:58PM (#16461409)
                (http://127.0.0.1/)
                It depends completely on what you're trying to accomplish.

                The AJAX model shines for web applications. You know, applications where you need to make frequent requests to the server. Flash can do this, but as others have said, you get the same latency issues with Flash making queries to the server as with an AJAX-like application.

                AJAX seems like a terrible idea for standalone applications, which is what you said in an earlier post. So far, I haven't seen a single AJAX application that didn't query a server somewhere. The reason for this is precisely because we have better options: Java/Flash if you want to stay in the browser, standalone applications if you don't.

                Maybe we've all just misunderstood you. Gmail is arguably the best-known AJAX application. Its primary user-interface is web-based. If you're suggesting that web-based e-mail is a ridiculous concept because you could just download a standalone client, download your messages, and read them off-line, I can see that as a valid viewpoint. But the reason that web applications exist (in general) is because nearly everyone has access to a web browser. You don't have to download a new program for each website you want to use. Imagine taking this idea to the extreme and having to download Google Internet Search rathern than just pointing your browser to http://www.google.com/ [google.com]. Wouldn't that seem a little weird (I'm old enough to have used Archie and Gopher, so no jokes about the young ones, please)

                Web browsers are good middleware because they're ubiquitous. Everyone who has an Internet connection has one. Using the functionality of the browser (much like the Java sandbox, incidentally, which you said was valid in http://books.slashdot.org/comments.pl?sid=200963&c id=16458167 [slashdot.org]) rather than writing a complete application has a number of advantages, not the least of which is version control (being able to ensure that people are using the latest version of your software, no version mismatches, etc).

                I think AJAX is an interesting model, and I'll be following its adoption with interest. I don't think it's the end-all be-all of computing, but I don't think it's completely without merit, either. Then again, I don't have anything against traditional web applications, for the most part, so that may be where our viewpoints differ.
                [ Parent ]
              • Re:Like regular applications, eh? by suparjerk (Score:1) Tuesday October 17 2006, @02:55AM
              • Re:Like regular applications, eh? by zero_offset (Score:2) Tuesday October 17 2006, @07:25AM
          • Re:Like regular applications, eh? by FunkyELF (Score:1) Wednesday October 18 2006, @09:49AM
    • Re:Like frames, eh? by DittoBox (Score:1) Monday October 16 2006, @04:06PM
    • 1 reply beneath your current threshold.
  • json (Score:2, Informative)

    by sirdisc (988740) on Monday October 16 2006, @02:41PM (#16457323)
    Google definitely didn't invent it. At this point I think more people are using JSON for the data format versus xml. There is just way too much overhead associated with xml. There are a host of javascript and other programming langauge libraries built up to make mall this more easy. For example, the dojo toolkit for javascript has functions for sending the request and decoding the JSON for you automatically. It also provides some framework for passing parameters, handlign errors, and more. Then JSON.org has a host of built up libraries in Java, Perl, C++, Ruby, ...(many many more) for encoding the data to send back. It's all very easy to do now.
  • Review reads like... (Score:3, Funny)

    by angelzero (935040) on Monday October 16 2006, @02:42PM (#16457333)
    ...a 4th grade book report.
  • yawn (Score:1, Informative)

    by Anonymous Coward on Monday October 16 2006, @02:45PM (#16457395)
    just get .net 2.0 and atlas [asp.net]
    • Re:yawn by ClosedSource (Score:2) Monday October 16 2006, @05:51PM
      • Re:yawn by Joey Vegetables (Score:2) Tuesday October 17 2006, @11:00AM
        • Re:yawn by ClosedSource (Score:2) Tuesday October 17 2006, @11:23AM
    • 1 reply beneath your current threshold.
  • Last time I... (Score:2, Funny)

    by Anonymous Coward on Monday October 16 2006, @02:48PM (#16457453)
    ...made a webpage out of AJAX, the FBI arrested me for attempting to poison the world as a terrorist act.
    • 1 reply beneath your current threshold.
  • AJAX (Score:5, Funny)

    My biggest problem with AJAX is the popular misconceptions that surround it. For example, I was speaking to somebody a few days ago and they asked me how I would implement some survey widget as a webpage. I thought about it for a bit and told them it would be pretty easy with some PHP and MySQL. I was informed that my idea is "old and outdated". It appears this guy had already hired somebody and he is "coding it in AJAX and Dreamweaver".

    I suggested that AJAX is nice, but it's not a programming language, and more importantly it is not always the best solution for a problem. His reply? That I need to get more "2.0 centric". I was done at this point, but not before informing him that Web 2.0 is little more than pastel colors and BS.

    Surprisingly, the reason he asked me in the first place is that the guy they hired has been working on the system for the last 3 months with "little visible progress". Oh well, at least he's "2.0" enough for them.
  • Ajax is... (Score:1, Funny)

    by SethEaston (920552) on Monday October 16 2006, @02:57PM (#16457593)
    Ajax is definitely at the forefront of what we think of as "Web 2.0" or Symantec Web technologies. The whole point of pushing web applications forward is to make them more like desktop applications that run natively (and I am not talking about Flash, Java applets, or stuff that requires 3rd-party software or requires stuff to run on the client machine except for JavaScript). In my mind, that is when the Symentec Web will finally arrive, and Google is already making it happen.
    • Re:Ajax is... by Anonymous Coward (Score:1) Monday October 16 2006, @03:02PM
    • Re:Ajax is... by jo42 (Score:2) Monday October 16 2006, @03:25PM
    • Re:Ajax is... by 955301 (Score:1) Monday October 16 2006, @03:36PM
      • Re:Ajax is... by uradu (Score:2) Monday October 16 2006, @04:42PM
      • Re:Ajax is... by GnuDiff (Score:1) Monday October 16 2006, @04:54PM
      • Re:Ajax is... by jazir1979 (Score:2) Monday October 16 2006, @06:31PM
        • Re:Ajax is... by 955301 (Score:2) Tuesday October 17 2006, @01:40PM
          • Re:Ajax is... by jazir1979 (Score:2) Tuesday October 17 2006, @04:09PM
      • Re:Ajax is... by ClosedSource (Score:3) Monday October 16 2006, @06:06PM
      • Re:Ajax is... by 955301 (Score:2) Tuesday October 17 2006, @01:33PM
        • Re:Ajax is... by sirdisc (Score:1) Tuesday October 17 2006, @09:36PM
          • Re:Ajax is... by sirdisc (Score:1) Tuesday October 17 2006, @09:38PM
      • 1 reply beneath your current threshold.
    • semantics... by chachacha (Score:1) Monday October 16 2006, @06:15PM
    • 1 reply beneath your current threshold.
  • by KalvinB (205500) on Monday October 16 2006, @03:03PM (#16457703)
    (http://www.icarusindie.com/)
    http://www.freeringtoneheaven.com/ [freeringtoneheaven.com] has tracked over 70,000 ips and about 64% have javascript enabled. At http://www.icarusindie.com/ [icarusindie.com] with 78,000 ips tracked only about 38% have javascript enabled.

    The only reason FRH is higher is because visitors were required to have javascript enabled in order to download ringtones. That restriction has been removed. Icarus Indie has never required javascript to be enabled. It just keeps statistics. The sites keep track by using javascript to switch an image from a jpg to a php script. Those without js just see the jpg and those with see the image returned by the php script which also updates the database to indicate the ip has js enabled.

    AJAX may be cool but if you use it you better have a good reason to convince people to turn javascript on or you're just going to lose visitors.

    There were all kinds of Javascript security issues not too long ago and people still don't trust it.
  • by darkchubs (814225) on Monday October 16 2006, @03:16PM (#16457939)
    This is the last Ajax post Im going to make... its getting silly at this point I get asked about it everyday. its not a language , its not even a standard... its a silicone valley buzzword made up by a guy named Jessy James . Ask someone to make you a www2 homepage for fear that your web 1.0 one will be outdated and not run on Windows vista in the long run the only winner in the hype is a hand full of early bandwagon companies (like my ajax company :) ) and Colgate-Palmolive who get all this free publicity. Ricahrd Corsale
  • XSLT (Score:3, Interesting)

    by gaspar ilom (859751) on Monday October 16 2006, @03:26PM (#16458131)
    I find it interesting that the review mentions XSLT, which, IMHO, is very powerful:

    You can completely separate most display logic from the "data" and business logic. (...which can be handled before the XSL transformation, and done such that you get XML nodes to feed into your transformations.)

    It may seem complicated at first, but there are so many advantages:

          1.) you get the layout of the site defined in a declarative manner, basically as as data. (and that XSL "code" can be easily analyzed or transformed, itself.)

          2.) you can disentangle a lot of markup from your PHP/ASP[VBS/JScript]/Python code.

          3.) The output of your XSLT transformation can be fed into other transformations.

          4.) Your XSLT is highly portable across platforms, even between server vs. client-side rendering.
    (Although, it bums me out that Microsoft has decided to not support XSL 2.0.)

          5.) Manipulating an X/HTML dom via a browser's built-in XSLT processor is much faster than using JavaScript only. (E.g.: using JavaScript-only to traverse a DOM in order to select, merge, append, and move nodes...)

    I'd be curious to know what this book has to say on the matter.

    • Re:XSLT by Ed Woychowsky (Score:1) Tuesday October 17 2006, @06:28AM
  • by se7en11 (833841) on Monday October 16 2006, @03:50PM (#16458509)
    Here's my couple of rules when to and when not to use AJAX (from experience)

    Do nots:
    1) Navigation - save yourself both time and effort and just pass varables in URLs.
    2) Application depend on it - like someone mentioned above, not everyone has Javascript enabled.

    Dos:
    1) Prevent popup windows - there's no reason to popup a window to make a small choice. Just switch the DIV with AJAX and make the choice done from within it.
    2) Small enhancments to a site - like to scrol through a couple news clips or something similar

    I'm sure there are more but I really need to get back to fixing my AJAX application-dependant-navigation-system. ;)
  • Ajax draw backs... (Score:1)

    by rHBa (976986) on Monday October 16 2006, @03:56PM (#16458657)
    No chapters about the many problems with most ajax implementations then? Namely:
    • Broken back button
    • No updates to browser history
    • The inability to link to an ajax populated web page

    I have built a few simple ajax apps but found the workarounds necessary to get these standard browser features working again not worth the effort in most cases.
  • by kippers (809056) on Monday October 16 2006, @04:08PM (#16458843)
    It is the people who think AJAX pages don't send requests over the internet that I worry about.

    'Oh, AJAX is cool, saves people having to wait for pages to load.' The content has got to come from sonewhere.
  • by lawman508 (969924) on Monday October 16 2006, @04:13PM (#16458937)
    I always think it's funny when people say that "Web 2.0" technologies are going to put Microsoft out of business. In fact, Microsoft OWA (Outlook Web Access) is by far the most popular, and in my opinion one of the best, AJAX programs released to date.
    • 1 reply beneath your current threshold.
  • by leighklotz (192300) on Monday October 16 2006, @04:20PM (#16459037)
    (http://www.graflex.org/klotz)
    Try AJAX with markup only, no hand-written JavaScript, by using the W3C [w3c.org]'s XForms [w3.org] standard. There are a number of implementations such as the Servlet-based Chiba [sourceforge.net] (which fronts for Dojo and other packages), FormFaces [formfaces.com] written entirely in JavaScript (no server-side component), entire server-side pipeline systems such as Orbeon [orbeon.com], and full client implementations such as the Mozilla/Firefox XForms Extension (just type "xforms" into your Firefox extensions finder), FormsPlayer IE Plugin [formsplayer.com], or cell-phone capable implementations such as PicoForms [picoforms.com] and SolidForms [sourceforge.net].

    I wrote an entire webmail reader using PHP for the back end and XForms for the client. It runs in the Mozilla XForms implementation but could easily be made to work in any of the above, which differ mostly in how the CSS works. xmlmail [graflex.org]

    And for completness, I was an editor of an earlier version of the W3C XForms recommendation.
  • by roman_mir (125474) on Monday October 16 2006, @04:39PM (#16459397)
    (http://booktextmark.mozdev.org/)
    I just had to explain to someone what AJAX meant and I did it in less than 300 seconds with the help of one of my tests that I created for one of the previous projects.

    Here is my test example, it is synchronous and it uses an evaluated array instead of XML, but those concepts can be explained in just another example of the same length:

    <HTML><SCRIPT LANGUAGE="JAVASCRIPT">
    <!--
    function handleHTTPResponseForArray(str) {

    // UNPARSED TEXT EXAMPLE
    handleHTTPResponse(str);

    // ARRAY EXAMPLE
    var textarea = document.getElementById("textarea2");
    var result=""; var array=eval(str); var hashMap=new Array(array.length);
    for(var i=0;i<array.length;i++) {
    hashMap[array[i][0]] = array[i][1];
    result += "key:" + array[i][0];
    result += "\t\t\tval:" + array[i][1] + "\n";
    }
    textarea.value=result;

    // HASH MAP EXAMPLE
    result="";
    for(var i=0;i<array.length;i++) {
    var tmpKey = array[i][0];
    result += "key(" + tmpKey + ")=" + hashMap[tmpKey] + "\n";
    }
    textarea = document.getElementById("textarea3");
    textarea.value = "Use result as a hash map with key/value pairs:\n";
    textarea.value += result;
    }

    function handleHTTPResponse(str) {
    var textarea = document.getElementById("textarea1");
    textarea.value=str;
    }

    function handleHTTPError(str) {
    alert(str);
    }

    function makeHTTPRequest(url, onLoadFunc, onErrorFunc) {
    var request;
    if(window.XMLHttpRequest) {
    try {
    request = new XMLHttpRequest();
    } catch(e) {
    alert(e);
    return;
    }
    } else if(window.ActiveXObject) {
    try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
    try {
    request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e1) {
    alert(e1);
    return;
    }
    }
    }
    try {
    window.status = "ECSM:AJAX:Connecting to "+ url;
    request.open("POST",url,false);
    request.setRequestHeader('Content-Type','applicati on/x-www-form-urlencoded; charset=UTF-8');
    request.send(null);
    window.status = "";
    } catch (e) {
    window.status = "";
    alert(e);
    return;
    }
    if (request.status==200) {
    onLoadFunc(request.responseText);
    } else {
    onErrorFunc(request.status);
    }
    }

    function testHTTPRequest() {
    var urltext = document.getElementById("urltext");
    makeHTTPRequest(urltext.value, handleHTTPResponseForArray, handleHTTPError);
    }
    //--></SCRIPT><BODY><table>< tr><td>URL:</t
  • Google? (Score:4, Insightful)

    by CDPatten (907182) on Monday October 16 2006, @05:12PM (#16460005)
    (http://www.pattensoap.com/)
    "think" is the important word when suggesting Google had something to do with AJAX. They have had NOTHING to do with it's creation seeing how that is up to the makers of web browsers. Microsoft really invented the functionality while most of the slashdotters were still getting wedgies in school.

    The term AJAX may have been coined a couple of years ago in an article, but MS deserves the credit. Its also worth noting they were using it on microsoft.com before most of us had even heard the word google.

    Lets see how many of you can swallow that and actually give them their do.
    • 1 reply beneath your current threshold.
  • Re:WHAT (Score:1, Funny)

    by WebHostingGuy (825421) * on Monday October 16 2006, @02:34PM (#16457197)
    (http://www.e3servers.com/ | Last Journal: Thursday January 26 2006, @12:17PM)
    Now, now Mel. You aren't supposed to be drinking in the middle of the day.
    [ Parent ]
    • 1 reply beneath your current threshold.
  • by darkchubs (814225) on Monday October 16 2006, @03:20PM (#16458027)
    you cant index the content in a flash SWF.. so making dyna sites with it would really hurt your chances of ranking on your target term.
    [ Parent ]
  • by Shados (741919) on Monday October 16 2006, @03:34PM (#16458287)
    Ultimately, AJAX is nothing more than spagetti Javascript and HTML.
    Thats why frameworks like ASP.NET AJAX (formerly known as Atlas) come in to solve that issue. When you use Atlas (a much more appropriate name than its new one, as Ajax is only a fraction of the framework), you get to use classes, inheritence, interfaces, and all around reusable constructs in your javascript. So it is anything BUT spagetti code.
    [ Parent ]
  • Re:WHAT (Score:1, Funny)

    by P3NIS_CLEAVER (860022) on Monday October 16 2006, @03:43PM (#16458405)
    (Last Journal: Wednesday January 25 2006, @05:44PM)
    Races that didn't do any fucking died out centuries ago.
    [ Parent ]
  • by fithmo (854772) on Monday October 16 2006, @03:49PM (#16458491)
    By the time Macromedia Flash v10.0 rolls out, AJAX will be relegated to the dustbin of technological history, much like Java applets...

    Really? Uh oh! Somebody better tell Google they need to redo all their apps in Flash, or they'll fail big time!

    [ Parent ]
  • by Scrameustache (459504) on Monday October 16 2006, @04:10PM (#16458881)
    (http://slashdot.org/ | Last Journal: Sunday September 09, @10:43PM)
    the typical end user (and most MacInfags) sure loves the stuff.

    You email your mother with that keyboard?
    [ Parent ]
  • by kippers (809056) on Monday October 16 2006, @04:11PM (#16458907)
    Yes, but adverts are so much more annoying in flash.
    [ Parent ]
  • by rHBa (976986) on Monday October 16 2006, @05:03PM (#16459861)
    ...they both break the standard features of your browser like a back button but at least ajax content is visible to search engine robots
    [ Parent ]
  • making my 2ghz CPU feel like a P2 running at 200mhz

    Don't worry, Vista will do that for you! Sure you don't want one of those Macinfags, you know, the one that has an OS that runs faster on the same hardware with each new release?
    [ Parent ]
  • Re:Flapjax (Score:2)

    by sammyo (166904) on Monday October 16 2006, @08:11PM (#16462133)
    (Last Journal: Tuesday February 11 2003, @02:39PM)
    Please please please tell me this does a server round trip
    transaction for each letter increment! Totally 'two dot O'

    http://www.flapjax-lang.org/demos/letter-count/run .html [flapjax-lang.org]
    [ Parent ]
    • 1 reply beneath your current threshold.
  • by LifesABeach (234436) on Tuesday October 17 2006, @12:27AM (#16464071)
    AJAX is the name given to the collection of language protocols of XML, XSLT, XSD, CSS, HTML, and Javascript. Microsoft would have you believe that you need a COM, or DOM object; But it is not necessary, and prone to cracking. It is best to start out with a client side XML page, and a XSLT line inserted to produce the web page. The top 4 browsers all can handle XML using the XSLT. If you need separate functionality, make use of a web service; Simple. And if you use this set of tools, your project completion will get done faster, and look better for it. Basically, many good things will happen if you include the AJAX set of tools.
    [ Parent ]
    • 1 reply beneath your current threshold.
  • 10 replies beneath your current threshold.