[TYPO3-ect] ajax and class per controller model
Steffen Kamper
steffen at sk-typo3.de
Fri Jun 29 09:54:30 CEST 2007
Hi,
ok - here is an example for populating a selectbox using eID. There is no
need fo xajax as the Ajax-Object is defined in prototype library, that has
to be included first
<script type="text/javascript" src="typo3/contrib/prototype.js"></script>
next is the use of some JS in page
function getCities() {
var url = "index.php";
var par1 = 2;
var par2 = document.getElementById('some_id').value;
var pars = "eID=myext&par1="+par1+"&par2="+par2;
var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars,
onComplete: updateCities});
}
function updateCities(orgRequest) {
var xmldoc = orgRequest.responseXML;
var result = xmldoc.getElementsByTagName("data")[0].firstChild.data;
document.getElementById('citydiv').innerHTML = result;
}
On element in the page uses the request getCities(); - in my case a
onchange-event.
Last step is to include an ajax.php (as example). This file has to be
registered, i use the ext_localconf.php:
$TYPO3_CONF_VARS['FE']['eID_include']['myext_ajax'] = 'EXT:myext/ajax.php';
'myext_ajax' is example, it has to be unique.
Ok, now we can do all the needed stuff in ajax.php:
<?php
// Exit, if script is called directly (must be included via eID in
index_ts.php)
if (!defined ('PATH_typo3conf')) die ('Could not access this script
directly!');
// Initialize FE user object:
$feUserObj = tslib_eidtools::initFeUser();
// Connect to database:
tslib_eidtools::connectDB();
$par1 = intval(t3lib_div::_GET('par1'));
$par2 = intval(t3lib_div::_GET('par2'));
// now generating the output
$res = '<select><option value="">alle</option></select>';
// and fire ...
$ajax_return_data = t3lib_div::array2xml(array('data'=>$res));
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate( "D, d M Y H:i:s" ) . 'GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Length: '.strlen($ajax_return_data));
header('Content-Type: text/xml');
echo $ajax_return_data;
exit;
?>
thats it.
vg Steffen
"Christian Welzel" <gawain at camlann.de> schrieb im Newsbeitrag
news:mailman.1.1183098354.5232.typo3-team-extension-coordination at lists.netfielders.de...
> Steffen Kamper wrote:
>
>> there are some nice functions for the ajaxfile. If you want i can post a
>> small example.
>
> Please do so.
> Would be perfect, if your example integrates xajax :)
>
> --
> MfG, Christian Welzel
>
> GPG-Key: http://www.camlann.de/key.asc
> Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15
More information about the TYPO3-team-extension-coordination
mailing list