473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

howto: please wait, this may take a few seconds...

what if i have a webpage that displays the text "please wait, this may take
a few seconds..." and it now waits until some event on the server happens.
whatever this is, this can be quick, but it could also be slow, or it can
even fail. but once this event has happened, i want the webpage to reload
and display a different message, like "the process completed successfully".

my question now is, how would i achieve this without constant visible
reloads? (which would probably be the simplest solution). is there a way to
do invisible polling via maybe a javascript (somewhere i picked up that
"ajax can do that")? what i want to achieve is that only if the event i was
waiting for actually occured, i want the webpage to actually visibly
reloaded, and displaying the new message.

what approach do for instance professional payment systems take, while the
client is waiting if the credit-card number is valid?

can someone push me in the right direction?
Sep 21 '05 #1
5 7829
hi , Erwin Kloibhofer

Actually i like your Quistion and i start to think how it could be ,
but it is can be in different part
1- you need to calculate php web page time execution.
2- you have to biuld your own template that may diplay an error or
status of submitted data if it is correct or not or waiting message.

but there is alot of method to do so.

i can give small code to execution time
like this
<!-- put this at the top of the page -->
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
<!-- put other code and html in here -->
<!-- put this code at the bottom of the page -->

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds";
or simply see this http://www.developerfusion.co.uk/show/2058/

so after you processing data you may need to check the time exeution
and and pass it to an HTML META tag as a parameter to display the
message that tell the user pleas wait a moment the META TAG may like
this

<META HTTP-EQUIV=\"Refresh\"
CONTENT=\"$X_sec; URL=$result_page\">

while $X_secis the time in second so the value of X will be got from
the above php code
and the HTML META tag may be reside on the top of the message template
inside the <head> tag .

and $result_page is the target page that go to next step if the data
are OK or the page that abort the process

test this page to for demo redirection
http://www.billstclair.com/html-redirect.html

---------------------------------------------------------------
anaother method you may need to create a function that display a
message and wait for data process by other function if the returned
value is valid you may go to next step or change the message if it is
invalid display error message or redirect the user to previuos page
---------------------------------------------------------------

i hope i give some Help
Regard

Sep 22 '05 #2
Erwin Kloibhofer wrote:
what if i have a webpage that displays the text "please wait, this may take
a few seconds..." and it now waits until some event on the server happens.
whatever this is, this can be quick, but it could also be slow, or it can
even fail. but once this event has happened, i want the webpage to reload
and display a different message, like "the process completed successfully".

my question now is, how would i achieve this without constant visible
reloads? (which would probably be the simplest solution). is there a way to
do invisible polling via maybe a javascript (somewhere i picked up that
"ajax can do that")? what i want to achieve is that only if the event i was
waiting for actually occured, i want the webpage to actually visibly
reloaded, and displaying the new message.

what approach do for instance professional payment systems take, while the
client is waiting if the credit-card number is valid?

can someone push me in the right direction?


You could use the onload() function in the <BODY> to redirect once the
page has finished, or use php to inject some javascript once your
processing is done, or get a little clever with the CSS visibility
property.

<html>
<head>
<style>
#waiting {
width: 100%;
height: 100%;
}
</style>
<script language=javascript>
function hide() {
h = eval('document.getElementById(\'waiting\')');
h.style.visibility = "hidden";
h.style.height = "0%";
}
</script>
</head>
<body onload="hide();">
<div id="waiting">
<center><br>
This may take a while!
</center>
</div

<?php

flush();
echo "doing something...... <br>";

sleep(10);

echo "Done <br>";
?>

Sacs
Sep 22 '05 #3
There are a number of ways to do an asynchronous look up through
Javascript. If you need something sophisticated, Google the web for
AJAX libraries.

A simple, cross-browser technique I've used before involves using
setInterval() to periodically call a function, which then dynamically
creates a <SCRIPT> tag linking in a PHP-generated script file. This
script file would contain just a call to a function already defined,
passing updated information from the server as parameter.

You could also do it without Javascript. Just print out a message,
perform the time-consuming task, then output a CSS style retroactively
to turn off the message.

Example:

<div id="test">
please wait, this may take a few seconds...
</div>
<?

// time consuming task

?>
<style>

#test {
display: none;
}

</style>

The trick here is in keeping the browser from timing out and proper
buffer flushing.

Sep 22 '05 #4

Chung Leong wrote:
There are a number of ways to do an asynchronous look up through
Javascript. If you need something sophisticated, Google the web for
AJAX libraries.

A simple, cross-browser technique I've used before involves using
setInterval() to periodically call a function, which then dynamically
creates a <SCRIPT> tag linking in a PHP-generated script file. This
script file would contain just a call to a function already defined,
passing updated information from the server as parameter.

You could also do it without Javascript. Just print out a message,
perform the time-consuming task, then output a CSS style retroactively
to turn off the message.

Example:

<div id="test">
please wait, this may take a few seconds...
</div>
<?

// time consuming task

?>
<style>

#test {
display: none;
}

</style>

The trick here is in keeping the browser from timing out and proper
buffer flushing.


You want a flush() after your div so it becomes visible. Otherwise, it
defeats the purpose.

<div id="test">
please wait, this may take a few seconds...
</div>
<?
flush();
// time consuming task

?>
<style>

#test {
display: none;
}

</style>

Sep 23 '05 #5
thanks for all your input, it did help a lot!

i came up with a piece of code that does exactly what i want. that is...

o) send out a page with a "this may take a while..." message
o) wait on the server until a certain event has happened
o) once it did happen, redirect to a different page

the only drawback i can see is that the browser keeps displaying "opening
page bla". that is something i can live with and i guess any other solution
that would avoid this would be too difficult to implement, where else the
current solution seems elegant and simple.

one problem i had to solve was to force the browser to do a full reload of
that page, and not taking the page from the cache. is there a more elegant
method to achieve this?

can anyone see any other problems with this code? what i am concerned about
is that after i sent the </body> and </html> tags i keep sending data...

================================================== ====

<?php
// create a header from the past to make sure the page does not get cached
header("Expires: Mon, 01 Jan 1999 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
<html>
<body onload="location.href='index.php'">
This may take a while...
</body>
</html>
<?php
if (ob_get_level() == 0) ob_start();
for ($i = 0; $i < 3; $i++)
{
echo "<b></b>"; // send some useless tags
echo str_pad('', 4096)."\n"; // send at least a 4K buffer
ob_flush();
flush();
sleep(2);
}
ob_end_flush();
?>
Sep 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason . | last post by:
I have seen a few articles with a javascript example but it is not working for me. The server side code is processed first and then the javascript so I basically get my page loading splash screen...
4
by: Dennis M. Marks | last post by:
I have multiple functions that dynamically build parts of a page. It can take 15-30 seconds for this process to complete. In IE nothing appears until the page is complete. In Netscape parts of the...
3
by: John Dalberg | last post by:
Hi I have a form that opens a new window for the results. Because the results might take a few seconds due to server processing, I would like to display a message "please wait" in the new...
2
by: Matt Culbreth | last post by:
Hello, I've got a fairly typical request to show a "Plese Wait" page while a long process is running. In this case, the user fills out a form, presses the button, a process searches for items,...
7
by: mw | last post by:
I'm writing an application that's going to do alot of processing while the user is waiting, (imagine sitting and waiting while the server/background processing is occurring). What's the best way...
4
by: puja patel | last post by:
hi all, I am developing a shopping cart website in C# where after selecting item, user enters credit card details and click on submit button.This request is then processed by the gateway which...
2
by: bigpoppa | last post by:
Hey I need help (doesn't everyone?) on a script. The script functions like this: Please wait X seconds for download (for example x=15 seconds) Please wait 14 seconds for download (and then a second...
7
by: adamalton | last post by:
Hi, I'm building a site where the user enters some info into a form which submits to a php script. The php script takes a long time to execute (anywhere from 10 seconds to a minute) and when it...
5
by: Jeremy | last post by:
Hi all, I have database actions that will potentially take several seconds to complete. My normal page uses AJAX so keeping the user informed of what is happening is not a problem. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.