basic xajax

25 10 2007

xajax adalah salah satu framework yang hebat dan senang digunakan apabila kita memahaminya.

Anda boleh menggunakan library xajax ini dalam code php anda dengan 7 langkah yang mudah:

  1. Panggil class library xajax ini dlm code php:
    require_once("xajax.inc.php");
        
  2. Instantiate objek xajax :
    $xajax = new xajax();
        
  3. Daftarkan nama function php yang anda inginkan membolehkan ia dipanggil melalui xajax :
    $xajax->registerFunction("myFunction");
        
  4. Tulis function PHP yang anda telah daftar dan guna xajaxResponse object untuk kembalikan XML commands :
    function myFunction($arg)
        {
            // do some stuff based on $arg like query data from a database and
            // put it into a variable like $newContent
    
            // Instantiate the xajaxResponse object
            $objResponse = new xajaxResponse();
    
            // add a command to the response to assign the innerHTML attribute of
            // the element with id="SomeElementId" to whatever the new content is
            $objResponse->addAssign("SomeElementId","innerHTML", $newContent);
    
            //return the  xajaxResponse object
            return $objResponse;
        }
        
  5. Sebelum script anda menghantar sebarang output, xajax handle any requests:
    $xajax->processRequests();
        
  6. Between your <head></head> tags, tell xajax to generate the necessary JavaScript:
    <?php $xajax->printJavascript(); ?>
  7. Panggil function dari JavaScript event atau function dalam aplikasi anda:
    <div id="SomeElementId"></div>
        <button onclick="xajax_myFunction(SomeArgument);">

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: