Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/complex_structure.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/complex_structure.php  >  Download  
File: tests/complex_structure.php
Role: Example script
Content type: text/plain
Description: Struct and array data retrieval
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:27
Size: 2,100 bytes
 

Contents

Class file image Download
<?php

require "../class.pAjax.php";


function 
complexStructure() {
    return array(
        array(
'prop' => 'value'),
        array(
'simple''another value'),
        
'someProperty' => 'someValue',
        
'another' => true,
        
'htmlTest' => '<b>Item</b>'
    
);
}


$AJAX = new pAjax;
$AJAX->disableDomainProtection();
$AJAX->enableExportProtection();
$AJAX->export("complexStructure");
$AJAX->handleRequest();

?>
<!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>Complex Structure Test</title>
        <?php $AJAX->showJavaScript(".."); ?>
        <script type="text/javascript">
            function ComplexStructure() {
                pAjax.call(this);
                pAjax.setDebugMode(true);
            }


            var _p = ComplexStructure.prototype = new pAjax;

            _p.execAction = function () {
                var oRequest = this.prepare("complexStructure", pAjaxRequest.POST);
                oRequest.execute(pAjaxRequest.SYNC); // Synchronized Mode Test
            }
            
            _p.onChange = function () {
                alert("Ready State: " + this.getReadyState());
            }

            _p.onLoad = function () {
                // getData is depreciate, use getResponse instead
                // Altho, getData is still supported for undeterminate period
                var data = this.getResponse();
                
                // Testing prefined property
                alert('Content of data[0].prop || data[0][\'prop\'] = ' + data[0].prop);
                
                for (var item in data) {
                    alert('Content of data[' + item + '] = ' + data[item]);
                            
                    //for (var innerItem in data[item]) {
                    //    alert('Content of data[' + item + '][' + innerItem + '] = ' + data[item][innerItem]);
                    //}
                }
            }
        </script>
    </head>
    
    <body>
        This example deals with a complex data structure returned by server (associative array and indexed array).<br />
        Check out the alerts to know how is it treated.<br />
        <br />
        <input type="button" value="Test!" onclick="(new ComplexStructure()).execAction();" />
    </body>
</html>