• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

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

0
sprnova
Asked:
sprnova
  • 2
  • 2
1 Solution
 
Roger BaklundCommented:
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;
0
 
sprnovaAuthor Commented:
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

0
 
Roger BaklundCommented:
"addAlert()" is a 0.2 method, in version 0.5 use "alert()":

$objResponse->alert("All done");
0
 
sprnovaAuthor Commented:
Thanks that works!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now