Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/obj_call.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Guilherme Blanco  >  pAjax  >  tests/obj_call.php  >  Download  
File: tests/obj_call.php
Role: Example script
Content type: text/plain
Description: Objects hierarchy test
Class: pAjax
Do RPC calls from the browser without page reloads
Author: By
Last change: - Updated tests to allow working with disabled domain protection and with
enabled export protection
Date: 2006-05-31 20:29
Size: 2,217 bytes
 

Contents

Class file image Download
<?php

require_once "../class.pAjax.php";


class 
Holder {
    var 
$sce;
    
    function 
Holder() {
        
$this->sce = new SpecialCharExample();
    }
}

    
class 
SpecialCharExample {
    function 
SpecialCharExample() { }

    function 
getIt($str) {
        return array(
substr($str, -21), strlen($str));
    }
}


$holder = new Holder();


$AJAX = new pAjax;
$AJAX->disableDomainProtection();
$AJAX->enableExportProtection();
$AJAX->export("holder.sce.getIt");
$AJAX->handleRequest("UTF-8"); // Default response charset is UTF-8

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>Special Char retriever</title>
        <?php $AJAX->showJavaScript(".."); ?>
        <script type="text/javascript">
              function Converter() {
                  pAjax.call(this);
                  pAjax.setDebugMode(true);
              }


              var _p = Converter.prototype = new pAjax;
              

              _p.convert = function (v) {
                  // Unlimited sub-objects supported
                  // In this example:
                  //
                  // + holder (class Holder)
                  // |-+ sce (class SpecialCharExample)
                  // | |-- getIt (method)
                  //
                  // Remember to set the property as public
                  //
                  // [TODO] Add support to factory calls. Currently, no factory is supported:
                  // $holder->getSce()->getIt($str)  <<< ERROR!
                var oRequest = this.prepare("holder.sce.getIt", pAjaxRequest.POST);
                oRequest.setParam("param", v);
                oRequest.execute(pAjaxRequest.ASYNC);
              }
              

              _p.onLoad = function () {
                var data = this.getResponse();
                
                alert("Retrieved text: " + data[0]);
                alert("Original length: " + data[1]);
              }
        </script>
    </head>

    <body>
        <input type="text" name="x" id="x" value="éõàüe" disabled="true" style="width: 50px;">
        <input type="button" name="check" value="Get Special Char (ü)"
            onclick="(new Converter()).convert(document.getElementById('x').value); return false;">
    </body>
</html>