Script.aculo.us Is My New Best Friend

Ajax is great. DOM manipulation is sexy. I'm fairly new to the Ajax world having only developed with with it since July. MasterWish was my guinea pig and continues to be my playground for all things Web 2.0. Luckily, my manager Ken is pumped up about this whole Web 2.0/Ajax thing which has allowed me to experiment with my projects at work as well and PSU should expect to see some sweet apps roll out over the next year!

Since July, I've been developing my Ajax applications and examples using SAJAX (Simple Ajax), a PHP/Javascript framework for Ajax development. It was great at first glance...a lot easier than building Asynchronous Javascript transactions from scratch. But despite its ease, it was a bit clunky. Last week I was stumbling around the web looking for anything new to suck up and found a beauty of a tool. Script.aculo.us.

Script.aculo.us is a Javascript Effects and Control framework developed by Thomas Fuchs, a software architect living in Vienna, Austria who, like me, was disappointed by current web application frameworks that made no sense to him. His framework is 3 things: Easy to Use, Simple, and Easy to Use. His libraries - built off of the Ajax framework, Prototype - blow SAJAX out of the water! Let me give you an example to, say, update a news title on an article (I won't include the HTML markup as that is trivial):

Here's what needs to be done to build a SAJAX call:

Step 1: Create a SAJAX Call Function

JavaScript:
  1. function x_updateTitle()
  2. {
  3.     sajax_do_call('/process_ajax.php',"x_updateTitle", x_updateTitle.arguments);
  4. }

Step 2: Create a server side function to handle the update

PHP:
  1. <?php
  2. function x_updateTitle($news_id,$news_title)
  3. {
  4.     //do some database calls to update the title;
  5. }
  6. ?>

Step 3: Edit the server side SAJAX file (process_ajax.php) and add x_updateTitle to the list of valid call functions

PHP:
  1. <?php
  2. include('sajax.php');
  3. addFunctions('x_updateTitle');
  4. handleClientRequest();
  5. ?>

Step 4: Call the SAJAX Javascript function from somewhere (in an onClick, onSubmit or something)

HTML:
  1. <a onClick="x_updateTitle(1, document.getElementById('news_title').value, 'callbackFunction');">asdfdf</a>

Here's the equivalent in Script.aculo.us
Step 1: Create a server side function to handle the update

PHP:
  1. <?php
  2. function x_updateTitle($news_id,$news_title)
  3. {
  4.     //do some database calls to update the title;
  5. }
  6. ?>

Step 2: Call the Script.aculo.us Javascript function from somewhere (in an onClick, onSubmit or something)

HTML:
  1. <a onClick="new Ajax.Request('/process_ajax.php', { asynchronous:true, parameters:'news_id=1&news_title=$(\'news_title\')', onSuccess:callbackFunction });">asdf</a>

Thats it! Its a big difference. Thats just the tip of the iceberg. Script.aculo.us has many features for implementing Drag and Drop with one line of Javascript code; fancy display/hide functions; dynamic DOM Element creation/deletion; field autocompletion; and various other visual effects. It slick. And to top it off, the Script.aculo.us website is pretty sweet! Luckily the documentation is excellent and is in wiki format. As Plymouth State moves into the Web 2.0 world, I'll be pushing for Script.aculo.us/Prototype to be our Ajax standard. I have seen the light and it is good.

Discuss This Article


22 Responses to “Script.aculo.us Is My New Best Friend”

  1. AvatarWandering Pig Effer

    Kinda disappointing that this library is not designed with OO methodologies, taking full advantage of PHP5 and its new features…

    One should be able to this:

    include(’sajax.php’);

    $objSajax = new Sajax();
    $objSajax->addFunctions(’x_updateTitle’);
    $objSajax->handleClientRequest();

    Perhaps its just me, but I tend to shy away from libraries that aren’t written for the latest version of the language they are written in.

    Reply to this comment.
    1
  2. AvatarMatt
    Author Comment

    Which is why SAJAX sucks and Script.aculo.us is groovy. Script.aculo.us, built on Prototype, is Object Oriented (well, as OO as you can get with Javascript) and leaves the PHP up to the developers.

    Reply to this comment.
    2
  3. pingback pingback:
    NoSheep! » Scriptaculous

    [...] Matt recently came across and got very excited about Script.aculo.us for doing DHTML effects and AJAX. [...]

    Reply to this comment.
    3
  4. pingback pingback:
    BorkWeb » Blog Archive » Node Manipulation in the DOM

    [...] I’ve been screwing around with DOM Manipulation for a few years now, doing stuff sporadically here and there. With my development of MasterWish and my recent interest in Script.aculo.us, I often find myself forgetting the various objects, functions and attributes relating to nodes. Hence the reason for this post. I want a quick and easy way to find the information…So, here’s a quick run-down of node structure: [...]

    Reply to this comment.
    4
  5. pingback pingback:
    BorkWeb » Blog Archive » Thomas Fuchs of Script.aculo.us: Ajaxian Podcast

    [...] Ajaxian has posted a podcast of their interview with Thomas Fuchs, the creator of Script.aculo.us. Ajaxian summarizes the content that is discussed: [...]

    Reply to this comment.
    5
  6. pingback pingback:
    BorkWeb » Blog Archive » Ajax; Templating; and the Separation of Layout and Logic

    [...] I have often mentioned my process of expanding my proficiency of Ajax. Through my journey I have made a number of wrong turns and hit my share of stumbling blocks. All of that has been a learning experience and I’m learning still. I began fiddling with XMLHttpRequest as many do - blissfully ignorant of the many frameworks that exist to make Ajax super easy. My code was bloated with some neat…’features’ (pronounced: bugs). [...]

    Reply to this comment.
    6
  7. AvatarFanis

    I feel that a reference to XAJAX is necessary here. I started off by using SAJAX, but now I’m hooked on XAJAX because of how easy it is to place the resulting html back into the document. No need for a callback there.

    Example server-side function:

    function dostuff($a) {
    $obj = new xajaxResponse() ;
    //perform whatever operation here
    $result1 = $a . “bla” ;
    $result2 = $a . “bli” ;
    $obj->addAssign(”div1″, “innerHTML”, $result1) ;
    $obj->addAssign(”div2″, “innerHTML”, $result2) ;
    $obj->addScript(”Element.show(’div1′);”) ;
    return $obj->getXML() ;
    }

    That’s it. The rest (calling the php function via javascript, as well as the setup) is similar to SAJAX. http://www.xajaxproject.org

    Fanis

    Reply to this comment.
    7
  8. pingback pingback:
    BorkWeb » Practicing What I Preach

    [...] MasterWish was built using SAJAX as the tool of choice for Ajax communication but as I’ve mentioned in the past, I am a Prototype convert. My knowledge of Ajax, JSON, and general application structure has been morphing so much in recent weeks that I have held off in completely revamping the wish list site. [...]

    Reply to this comment.
    8
  9. pingback pingback:
    BorkWeb » Script.aculo.us v1.6 Soon

    [...] Great news over at Mir.aculo.us. It appears as if version 1.6 of my favorite DOM manipulation library, Script.aculo.us will be out soon. Thankfully the new version of Script.aculo.us will be using Prototype v1.5. [...]

    Reply to this comment.
    9
  10. pingback pingback:
    BorkWeb » The Case For JSON: What Is It and Why Use It?

    [...] As Ajax methodologies (and even Cross Domain Scripting) become more commonplace, data format becomes vital to the efficiency of our applications. The Zimbra folks seem to have realized this and subsequently re-architected their entire application. Oh, and Script.aculo.us creator Thomas Fuchs seems to agree and stats his opinion on XML in Ajax communication: Its dog slow…don’t do it. [...]

    Reply to this comment.
    10
  11. AvatarRudi

    Hi,

    Could you publish a couple of simple database example using both Sajax and Script.aculo
    to see the difference more clearly. Thanks.

    I’m having a hard time trying to get something to work against a database. I use Oracle.

    Have a nice day and thanks in advance for the reply.

    Regards,

    Rudi

    Reply to this comment.
    11
  12. pingback pingback:
    programania » Javascript, ajax, jSon, Prototype y scriptaculous 12
  13. AvatarRon

    Check out http://www.planjam.com/date.php

    The site urelies heavily on AJAX, uses Prototype, and does an excellent job with many aspects of the script.aculo.us library.

    Reply to this comment.
    13
  14. Avatartest

    this is to see how comments look

    Reply to this comment.
    14
  15. AvatarAlex

    I prefer Sajax, because I managed to learn it and fully understand it, and it’s actually easy to use.

    Sajax is way better :D… really
    Sajax rulez!

    Reply to this comment.
    15
  16. pingback pingback:
    BorkWeb » Learning What I Know

    [...] THEN tackle Prototype and Script.aculo.us [...]

    Reply to this comment.
    16
  17. Avatarkatalog

    The problem comes when the “pros” that develop such libraries widely demonstrate uses that are blatantly bad from a usability point of view. They should be encouraging good uses, not promoting bad ones.

    Reply to this comment.
    17
  18. pingback pingback:
    BorkWeb » The Ajax Experience: jQuery Toolkit

    [...] I went to The Ajax Experience with high expectations of catching some great tips regarding development in an Ajax environment. At the same time, I was sure of my previous decision with the use of Prototype and Script.aculo.us was as good as it gets (without diving into the widgetized world…e.g. Dojo). I attended John Resig’s presentation on jQuery and I became a convert. [...]

    Reply to this comment.
    18
  19. Avatarpogoń świerzawa

    Nice:)
    They should be encouraging good uses, not promoting bad ones.

    Reply to this comment.
    19
  20. Avatarjewellery

    Hmmm… I think this is the third time I’ve heard about scriptaculous this week. Must be a sign! I haven’t tried SAJAX out yet, but am glad to hear about both SAJAX and Scriptaculous, as I’m also just starting (and only just) at looking at AJAX. Haven’t used it yet, but the concept is great. This is fantastic, perhaps this will mean a lot less time wasted. Thanks for this!

    Reply to this comment.
    20
  21. Avatarportrait oil painting

    Are you sure you’re new to this? It looks like you’re already a pro. Thanks for a very detailed post. I’m trying to consolidate everything and trying them out myself so I can share them to my students.

    Reply to this comment.
    21
  22. Avatarqwieqowoeu

    very good site

    Reply to this comment.
    22

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment Preview:

 (8671) - scriptaculous drop down menu (90) - script.aculo.us (86) - scriptaculous menu (78) - scriptaculous examples (57) - scriptaculous dropdown (52) - scriptaculous menus (51) - menu scriptaculous (37) - scriptaculous drop down (33) - script.aculo.us menu (30) - scriptaculous oncomplete (25) - scriptaculous droppable (20) - Drop down Menu scriptaculous (20) - scriptaculous php (19) - scriptaculous dropdown menu (16) - scriptalicious menu (14) - script.aculo.us drop down menu (14) - scriptaculous tab (13) - scriptaculous drop (13) - scriptaculous php autocomplete (13) - script.aculo.us examples (13) - scriptaculous samples (12) - script.aculo.us autocomplete php (10) - scriptaculous hover (10) - php scriptaculous (10) - scriptaculous tabs (9) - xajax autocomplete (8) - Script.aculo.us tab (8) - script.aculo.us tabs (8) - menu script.aculo.us (7) - scriptalicious tutorial (7) - autocomplete scriptaculous (7) - scriptaculous horizontal menu (7) - scriptalicious examples (6) - scriptaculous effect oncomplete (6) - scriptaculous select menu (6) - autocomplete scriptaculous php (6) - scriptaculous vertical menu (6) - scriptaculous menu example (5) - autocomplete xajax (5) - script.aculo.us dropdown menu (5) - prototype scriptaculous menu (5) - scriptaculous autocomplete php (5) - scriptaculous autocompleter php (5) - xajax scriptaculous (5) - scriptaculous tab menu (5) - scriptaculous example (5) - scriptaculous database (5) - scriptaculous (5) - best scriptaculous (4) - scriptaculous onclick (4) - scriptaculous facebook (4) - script.aculo.us autocomplete (4) - scriptaculous drop down list (4) - scriptaculous javascript menu (4) - sajax drag drop (4) - dropdown scriptaculous (4) - vertical menu scriptaculous (4) - scriptaculous menu vertical (4) - examples scriptaculous (4) - scriptalicious tabs (4) - scriptaculous drop-down menu (4) - scriptaculous pulldown (4) - javascript menu scriptaculous (4) - scriptaculous drop down menus (4) - facebook scriptaculous (3) - scriptaculous autocomplete parameters (3) - How to use script.aculo.us autocomplete with .net (3) - scriptaculous menu effect (3) - script.aculo.us php autocomplete (3) - drop down menu with scriptaculous (3) - scriptaculous examples draggable (3) - scriptalicious drop down menu (3) - scriptaculous expanding menu (3) - sajax autocomplete (3) - scriptaculous hover menu (3) - scriptaculos dropdown (3) - script.aculo.us autocompleter php (3) - Scriptaculous php example (3) - Autocomplete php scriptaculous (3) - php scriptaculous autocomplete (3) - how do you pronounce scriptaculous (3) - scriptaculous dropdownlist (3) - scriptaculous drop down menu tutorial (3) - scriptaculous pull down menu (3) - prototype scriptaculous examples (3) - menu contextuel script.aculo.us (3) - jquery cascade drop down (3) - script.aculo.us drag and drop tutorial (3) - script.aculo.us drop down (3) - scriptaculous list (3) - script (3) - dynamic menu scriptaculous (3) - dropdown menu scriptaculous (3) - script.aculo.us dropdown (3) - json scriptaculous (3) - menus scriptaculous (3) - script aculo menu (3) - script.aculo.us php (3) - sajax examples (3) - scriptaculous drag drop example (2) - drag to tab scriptaculous (2) - scriptaculous autocompleter (2) - menu avec Scriptaculous (2) - scriptaculous drop downs (2) - scriptaculous drag drop example -ruby (2) - javascript scriptaculous menu (2) - example scriptaculous xajax (2) - scriptalicious expanding menu (2) - pronounce script.aculo.us (2) - autocomplete scriptaculous tutorial php (2) - scriptaculous site structure (2) - scriptaculous dynamic list (2) - php and scriptaculous (2) - implementing aculo us with ajax (2) - scriptaculous menu examples (2) - scriptaculous web menu (2) - scriptaculous lava menüs (2) - scriptaculous vertical text (2) - Scriptaculous new Droppable (2) - scriptaculous effect menu (2) - lava menu scriptaculous (2) - script.aculo.us/ example (2) - scriptaculous menü (2) - dhtml menu scriptaculous (2) - autocomplete scriptaculous with php (2) - scriptaculous menu up down (2) - prototype visual effects dropdown (2) - scriptaculous dynamic menu (2) - prototype scriptaculous drop down menus (2) - scriptaculous autocomplete dynamic (2) - exemples scriptaculous droppable (2) - scriptaculous horizontal dropdown menu animado (2) - Script.aculo.us tab menu (2) - menu horizontal scriptaculous (2) - scriptaculous and php (2) - scriptaculous rollup (2) - html drop down menu scriptaculous (2) - script.aculo.us dhtml menu (2) - scriptaculous with PHP (2) - scriptaculous droppable example (2) - scriptaculous.js menu (2) - Scriptaculous Tutorial (2) - menu déroulant script.aculo.us (2) - asp.net script.aculo.us autocomplete (2) - scriptaculous menu drop down (2) - script.aculo.us tutorial menu (2) - drop down menu script.aculo.us (2) - scriptaculous autocomplete tutorial php (2) - script.aculo.us menu dropdown (2) -