different loading messages in xajax framework

Using xajax 0.5 rc1, you can now use the following (callback objects) to accomplish this:

loadingPage = xajax.callback.create(300, 10000);
loadingSomeSelectOptions = xajax.callback.create(300, 10000);
loadingOtherSelectOptions = xajax.callback.create(100, 10000);

Then, provide the operations to perform:

loadingPage.onResponseDelay = function() { ... show loading message ... }
loadingPage.onComplete = function() { ... hide loading message ... }

loadingSomeSelectOptions.onRequest = function() { ... show loading message over select box ... }
loadingSomeSelectOptions.onComplete = function() { ... hide loading message ... }

loadingOtherSelectOptions.onResponseDelay = function() { ... show loading msg over other select box ... }
loadingOtherSelectOptions.onComplete = function() { ... hide loading message ... }

Then:

xajax.call('loadPage', { callback: loadingPage });
xajax.call('loadSomeSelectOptions', { callback: loadingSomeSelectOptions });
etc...

As an alternative, you could even:

showLoading = function(oRequest) {
  if ('loadPage' == oRequest.functionName) { ... show page loading message ... }
  else if ('loadSomeSelectOptions' == oRequest.functionName) { ... show loading message over select ... }
}

hideLoading = function(oRequest) {
  if ('loadPage' == oRequest.functionName) { ... hide page loading message ... }
  else if ('loadSomeSelectOptions' == oRequest.functionName) { ... hide loading message ... }
}

handleLoadingMessage = xajax.callback.create(400, 10000);
handleLoadingMessage.onResponseDelay = showLoading;
handleLoadingMessage.onComplete = hideLoading;

xajax.call('loadPage', { callback: handleLoadingMessage });
detail here: http://community.xajaxproject.org/viewtopic.php?pid=13840#p13840


example:
<?php
require_once("xajax_core/xajax.inc.php");
$xajax = new xajax();
// SEE file list below!
$xajax->setFlag("debug", false);

$xajax->registerFunction("callScript0");
$xajax->registerFunction("callScript1");
$xajax->registerFunction("callScript2");
$xajax->registerFunction("callScript3");

function callScript0()
{
$response = new xajaxResponse();
$value = "this is a string duoc tra ve";
for($i=0;$i<10000000;$i++){
$j += $i;
}
$response->assign("display0", "innerHTML", nl2br(print_r($value." - ".$i." - ".$j, true)));
return $response;
}
function callScript1()
{
$response = new xajaxResponse();
$value = "this is a string duoc tra ve";
for($i=0;$i<10000000;$i++){
$j += $i;
}
$response->assign("display1", "innerHTML", nl2br(print_r($value." - ".$i." - ".$j, true)));
return $response;
}
function callScript2()
{
$response = new xajaxResponse();
$value = "this is a string duoc tra ve";
for($i=0;$i<10000000;$i++){
$j += $i;
}
$response->assign("display2", "innerHTML", nl2br(print_r($value." - ".$i." - ".$j, true)));
return $response;
}
function callScript3()
{
$response = new xajaxResponse();
$value = "this is a string duoc tra ve";
for($i=0;$i<10000000;$i++){
$j += $i;
}
$response->assign("display3", "innerHTML", nl2br(print_r($value." - ".$i." - ".$j, true)));
return $response;
}
$xajax->processRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>xajax Tests</title>
<?php
$xajax_files = array();
$xajax_files[] = array("xajax_js/xajax_core.js", "xajax");
// $xajax_files[] = array("xajax_js/xajax_debug.js", "xajax.debug");
$xajax->printJavascript("", $xajax_files)
?>
<script type="text/javascript">
<!--
loadingPage0 = xajax.callback.create(300, 10000);
loadingPage1 = xajax.callback.create(300, 10000);
loadingPage2 = xajax.callback.create(300, 10000);
loadingPage3 = xajax.callback.create(300, 10000);

loadingPage0.onResponseDelay = function() {
xajax.$('display0').innerHTML = "Global Loading0, please wait a moment...";
}
loadingPage0.onComplete = function() {
//xajax.$('loading0').style.display = 'none';
}

loadingPage1.onRequest = function() {
xajax.$('display1').innerHTML = "Global Loading1, please wait a moment...";
}
loadingPage1.onComplete = function() { xajax.$('loading1').style.display = 'none'; }

loadingPage2.onResponseDelay = function() { xajax.$('loading2').style.display = 'block'; }
loadingPage2.onComplete = function() { xajax.$('loading2').style.display = 'none'; }

loadingPage3.onRequest = function() { xajax.$('loading3').style.display = 'block'; }
loadingPage3.onComplete = function() { xajax.$('loading3').style.display = 'none'; }
// -->
</script>
</head>
<body>
<div id="loading0" style="display:none; color:#000033;">Global Loading0, please wait a moment...</div>
<div id="loading1" style="display:none; color:#000033;">Global Loading1, please wait a moment...</div>
<div id="loading2" style="display:none; color:#000033;">Global Loading2, please wait a moment...</div>
<div id="loading3" style="display:none; color:#000033;">Global Loading3, please wait a moment...</div>
<p><input type="button" value="Click Me 0" onclick="xajax.call('callScript0', { callback: loadingPage0 })" /></p>
<p><input type="button" value="Click Me 1" onclick="xajax.call('callScript1', { callback: loadingPage1 })" /></p>
<p><input type="button" value="Click Me 2" onclick="xajax.call('callScript2', { callback: loadingPage2 })" /></p>
<p><input type="button" value="Click Me 3" onclick="xajax.call('callScript3', { callback: loadingPage3 })" /></p>

<div id="display0"></div>
<div id="display1"></div>
<div id="display2"></div>
<div id="display3"></div>
</body>
</html>
########################################################
myCallBackObject = xajax.callbacks.create( *1, *2 )
*1 = response delay time
*2 = expiration timeout
both are optional

########################################################

Nhận xét

Bài đăng phổ biến từ blog này

Ký tự viết tắt trong chat & email

dung lượng RAM lớn nhất mà HĐH cấu trúc 32-bit nhận được

Ubuntu LAMP Server