Ajaxorized

JSON in prototype 1.6.0: basic example

October 4, 2007

That right guys, prototype 1.6.0 is on it's way and there is one aspect I want to share with you. In stead of using the old-fashioned 'http-header' way to transport JSON, the prototype framework now eats files with the content-type 'application/json'. A short example:

  1. First, we will use prototype to make an ajax request.
     new Ajax.Request('ajax.php',{ onSuccess: handleSuccess }, method: 'get' });
  2. After this, on the serverside we set the json headers and output the formatted data using the Services_JSON class:
    <?php
    require_once "services_json.class.php";
     
    /* Set the JSON header */
    header("content-type:application/json");
     
    /* Format some data */
    $aData = array("Car", "Plane", "Train");
     
    $oJson = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
     
    /* Output */
    echo $oJson->encode($aData);
    ?>
  3. And finally this alerts 'Car', 'Plain' and 'Train':
    function handleSuccess(transport) {
      $A(transport.responseJSON).each(function(str) {
        alert(str);
      });
    }

Add to: del.icio.us Reddit Slashdot Digg Facebook Technorati Google StumbleUpon Windows Live Yahoo
topFiled under: Ajax, Prototype, Javascript | Willem @ 1:16 am | Comments (1)

Top 5 FireFox plugins for serious webdevelopment

July 10, 2007

Once, long before the Ajax and Web 2.0 era , there was a time we used HTML <center> for text-alignment and javascripts stunning alert() function for debugging our websites and applications. But times are changing. To develop high performance Web 2.0 'killer apps', we need more tools and better applications to create web applications based upon Javascript frameworks (such as prototype, jQuery, scriptaculous, moo tools etc.) feeded by PHP as a backend. Below I will sum up some free Firefox-extensions to build web applications quick, efficient and flawless. Ok, almost flawless then. (more...)

Add to: del.icio.us Reddit Slashdot Digg Facebook Technorati Google StumbleUpon Windows Live Yahoo
topFiled under: Ajaxorized, Ajax, Javascript | Willem @ 9:50 pm | Comments (1)