[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TYPO3-dev] Trying to get my head around AJAX

Dear Simon,

Having encountered the same 'lack' of a description of one of the stronger possibilities of xajax, and simply not having had the time to delve into it some more, I am more than happy with and very grateful for your contribution.

Ton Akveld

Fr. Simon Rundell SCP schreef:
Dear Jochen et al

Thank you! I have success using xajax! I eventually hacked up the
xajax tutorial to perform a database query. It's funny that virtually
all the AJAX examples are all to do with css style modifications and
say very little about asych data querying which is really its
strongest possibility.

For the record and the benefit of others starting this road, here are
the core parts of the proof of concept before I try and turn it into
something useful  :-)  -

Plugin Main function:

function main($content,$conf)   {

                require_once (t3lib_extMgm::extPath('xajax') . 
                $this->xajax = t3lib_div::makeInstance('tx_xajax');
                // Turn only on during testing
                // Register the names of the PHP functions you want to be able 
call through xajax
                // $xajax->registerFunction(array('functionNameInJavascript',
&$object, 'methodName'));
                $this->xajax->registerFunction(array('processFormData', &$this,
                $GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] =

$content .= '<h2>Ajax Development Test Plugin</h2>';
$content .= '
<form name="submittest" id="submittest"
Field:<input type="text" name="field" id="field" size="20" value="surname"><br>
Table:<input type="text" name="table" size="30" id="table"
Criteria:<input type="text" name="criteria" size="50" id="criteria"
<input type="button" onclick="' . $this->prefixId .
'processFormData(xajax.getFormValues(\'submittest\'))" value="Query
MySQL" >

<div id="results">
Results Here
                return $this->pi_wrapInBaseClass($content);
} // end of main

// now the two key functions in PHP

function sGetFormResult($field, $table, $criteria)      {
// could be any kind of database query, here is a generic wrapper

        $sql="SELECT $field FROM $table WHERE $criteria";
        $result = mysql_query($sql) or die("Basic Lookup: <i>$sql</i> failed
with error: ".mysql_error());
        # make sure that we recieved some data from our query
        $num_of_rows = mysql_num_rows ($result);
        if($num_of_rows==0) {
                return 'NOT FOUND'; }
        else {
                while ($row = mysql_fetch_array ($result)) {    
                } // while

return $return_object;

} // function sGetFormResult()

function processFormData($data) {

        $this->piVars = $data[$this->prefixId];
        $content = $this->sGetFormResult($data["field"], $data["table"],
        $objResponse = new tx_xajax_response();
        $objResponse->addAssign('results', 'innerHTML',
        return $objResponse->getXML();

} // function processFormData($data)

I hope this helps someone.

Fr. Simon Rundell SCP
Parish of S. Thomas the Apostle, Elson
The Vicarage, 21 Elson Road, Gosport, Hants, UK, PO12 4BL
Tel: 02392 582824 Mob: 07976 802123
email: [email protected]
web: http://www.saintthomaselson.org.uk
blog: http://frsimon.wordpress.com

"I came that you may have life - life in all its fullness"
 John 10:10

2008/4/29 Jochen Rieger <[email protected]>:
Hi Simon,

I'd propose two alternatives:

1) use the xajax extension... it's fairly easy to use. You will have to
set up a response object which can call several functions eg to update
your HTML code or popup an alert message etc. (the functions will be
found in the xajax response class).

TYPO3-dev mailing list
[email protected]
TYPO3-dev mailing list
[email protected]