Link to home
Start Free TrialLog in
Avatar of sprnova
sprnova

asked on

Xajax function not triggering event

I am using the following code found in an online tutorial to learn xajax but nothing comes up in the onclick event. Can anyone tell me what I am doing wrong?
<?php
require_once ("xajax/xajax_core/xajax.inc.php");
 
function slow_function()
{
    $objResponse = new xajaxResponse();
    sleep(2); //we'll do nothing for two seconds
    $objResponse->addAlert("All done");
    return $objResponse;
}
 
$xajax = new xajax();
$xajax->registerFunction('slow_function');
$xajax->processRequest();
?><html>
    <head>
        <title>Loading Bar Demo</title>
        <? $xajax->printJavascript('xajax/'); ?>
    </head>
    <body>
        <script type="text/javascript">
        <!--
            xajax.loadingFunction = 
                function(){xajax.$('loadingMessage').style.display='block';};
            function hideLoadingMessage()
            {
                xajax.$('loadingMessage').style.display = 'none';
            }
            xajax.doneLoadingFunction = hideLoadingMessage;
        // --></script>
        <input type="button" onclick="xajax_slow_function();" value="Slow Function" />
        <div id="loadingMessage" style="font-size: 22px; display: none;">
            Loading...
        </div>
    </body>
</html>

Open in new window

Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

What version of xajax are you using? If it is version 0.5, change this:

            xajax.loadingFunction =
                function(){xajax.$('loadingMessage').style.display='block';};
            function hideLoadingMessage()
            {
                xajax.$('loadingMessage').style.display = 'none';
            }
            xajax.doneLoadingFunction = hideLoadingMessage;

...into this:

            xajax.callback.global.onRequest=
                function(){xajax.$('loadingMessage').style.display='block';};
            function hideLoadingMessage()
            {
                xajax.$('loadingMessage').style.display = 'none';
            }
            xajax.callback.global.beforeResponseProcessing=hideLoadingMessage;
Avatar of sprnova
sprnova

ASKER

This displays the loading message but still no alert box.
<?php
require_once ("xajax/xajax_core/xajax.inc.php");
 
function slow_function()
{
    $objResponse = new xajaxResponse();
    sleep(2); //we'll do nothing for two seconds
    $objResponse->addAlert("All done");
    return $objResponse;
}
 
$xajax = new xajax();
$xajax->registerFunction('slow_function');
$xajax->processRequest();
?><html>
    <head>
        <title>Loading Bar Demo</title>
        <? $xajax->printJavascript('xajax/'); ?>
    </head>
    <body>
        <script type="text/javascript">
        <!--
           xajax.callback.global.onRequest=
                function(){xajax.$('loadingMessage').style.display='block';};
            function hideLoadingMessage()
            {
                xajax.$('loadingMessage').style.display = 'none';
            }
            xajax.callback.global.beforeResponseProcessing=hideLoadingMessage;
        // --></script>
        <input type="button" onclick="xajax_slow_function();" value="Slow Function" />
        <div id="loadingMessage" style="font-size: 22px; display: none;">
            Loading...
        </div>
    </body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sprnova

ASKER

Thanks that works!