Topic: Display a message or image when a request is in process

Often, we want to notify the end user that an operation is in process; to let them know they may need to wait a bit for the operation to finish. 

First, let's define the message, what to do to show the message and what to do to hide the message:
<script type="text/javascript">
    <!--
        showLoading = function() {
            xajax.$('loading').style.display='block';
        };
        hideLoading = function() {
            xajax.$('loading').style.display = 'none';
        }
    // -->
</script>

and later (in the HTML of the page):
<div id='loading'>Loading, please wait a moment...</div>

----------
With xajax 0.2.4 (the current release), you can accomplish this with the following javascript code:

<script type="text/javascript">
    <!--
        xajax.loadingFunction = showLoading;
        xajax.doneLoadingFunction = hideLoading;
    // -->
</script>

----------
With xajax 0.5 (the current beta release), you can accomplish this with the following javascript code:

on a global level:
<script type="text/javascript">
    <!--
        xajax.callback.global.onResponseDelay = showLoading;
        xajax.callback.global.onComplete = hideLoading;
    // -->
</script>


on a per call basis:
<script type="text/javascript">
    <!--
        xajax_loadPage = function() {
            handleLoadingMessage = xajax.callback.create(400, 10000);
            handleLoadingMessage.onResponseDelay = showLoading;
            handleLoadingMessage.onComplete = hideLoading;

            xajax.call('loadPage', { callback: handleLoadingMessage });
        }
    // -->
</script>

----------
With xajax 0.5, you have more flexibility.  Instead of a single loading message, you can now define a variety of loading messages.  In addition, you can use two or more loading messages simultaneously.

please see this post for a detailed description:
http://community.xajaxproject.org/viewt … 840#p13840

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: Display a message or image when a request is in process

With xajax 0.5 beta 4 there was some changes and there is a interesting undocumented thing:

If you want to have access to the function-name that was called you should use now:


    xajax.callback.global.onRequest = function(oRequest)
    {        
        if ( oRequest.functionName.xjxfun.match(/save/) )
        {
 // do something
        }
        if ( oRequest.functionName.xjxfun.match(/load/) )
        {
 // do something
        }
    }            
    xajax.callback.global.onComplete = function(oRequest)
    {        
        if ( oRequest.functionName.xjxfun.match(/save/) )
        {
 // do something
        }
        if ( oRequest.functionName.xjxfun.match(/load/) )
        {
 // do something
        }
    }

Re: Display a message or image when a request is in process

please, can you to show all the example? I need one complete example, Thanks

Re: Display a message or image when a request is in process

Thanks for the above information. Please do posting.

Re: Display a message or image when a request is in process

Here's a sample

<?php
require_once("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');

function sleepOnIt()
{
  $resp = new xajaxResponse();
  sleep(3);
  $resp->alert('Success');
  return $resp;
}

$xajax->register(XAJAX_FUNCTION,'sleepOnIt');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<title>Global Callback Testing</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
  <!--
  xajax.callback.global.onResponseDelay = showLoading;
  xajax.callback.global.onComplete = hideLoading;
  
  function showLoading() {xajax.$('loading').style.display='block';}
  function hideLoading() {xajax.$('loading').style.display = 'none';}  
  -->  
</script>
</head>
<body>
<input type="button" value="Click Me" onclick="xajax_sleepOnIt();"/>
<br/><br/>
<div id='loading' style="display:none;">Loading, please wait a moment...</div>
</body>
</html>

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.