[TYPO3-dev] xajax !! several extension using xajax on the same page of typo3 throwing errors

Mauro Lorenzutti mauro.lorenzutti at webformat.com
Tue May 20 17:02:57 CEST 2008


Hi Nirmalya,

> Hello,
>
> I am developing an extension that has two FE plugin (pi1, pi2).
> Both of plugins (pi1, pi2) are using xajax extension and are working 
> fine on different typo3 page(say page id=15, 16). But when i am 
> inserting both plugin (pi1, pi2) on same typo3 page (say page id=15) 
> xajax is throwing errors. That error is an alert message i.e. "Unknown 
> Function MyRegisterFunctionName".
> It also happening for two different extension (using xajax library) too.
> Anybody faced that same ploblem...
> please help me to resolve it or any clue..
>   

I solved in this way (not the best one but the only one I found...):

I created a global var with the xajax object:

global $lm_xajax;

then I initialize the object if it has not been initialized yet:

if (!is_object($lm_xajax))    {
                require_once (t3lib_extMgm::extPath('xajax') . 
'class.tx_xajax.php');
                // Make the instance
                $lm_xajax = t3lib_div::makeInstance('tx_xajax');
                // Decode form vars from utf8 ???
                $lm_xajax->decodeUTF8InputOn();
                // Encode of the response to utf-8 ???
                $lm_xajax->setCharEncoding('utf-8');
                // To prevent conflicts, prepend the extension prefix
                $lm_xajax->setWrapperPrefix('c4baby_');
                // Do you wnat messages in the status bar?
                $lm_xajax->statusMessagesOn();
               
                $reqURI = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
                if (strpos($reqURI, '?')>0)
                    $reqURI .= '&no_cache=1';
                else
                    $reqURI .= '?no_cache=1';
                $lm_xajax->setRequestURI($reqURI);
            }

Then I register my functions as usual:

$lm_xajax->registerFunction(array('searchRecipe', &$this, 'searchRecipe'));

// If this is an xajax request, call our registered function, send 
output and exit
$lm_xajax->processRequests();
// Else create javascript and add it to the header output
$GLOBALS['TSFE']->additionalHeaderData['c4baby_'] = 
$lm_xajax->getJavascript(t3lib_extMgm::siteRelPath('xajax'));


I hope this can help you.

The problem is that only one xajax object is allowed for page. In this 
way, you can register only one object in a lot of extensions.

Regards,

-- 
 Mauro Lorenzutti

e-mail:  mauro.lorenzutti at webformat.com
---------------------------------------------------------
WEBFORMAT srl | Corte Europa, 12 | I-33097 SPILIMBERGO PN
     Tel +39-0427-926.389  --  Fax +39-0427-927.653
       info at webformat.com  --  http://www.webformat.com
---------------------------------------------------------





More information about the TYPO3-dev mailing list