This topic is locked
[SOLVED]

 Page refresh controlled by database

9/18/2012 9:52:14 AM
PHPRunner General questions
C
ckranich authorDevClub member

Hello,
To indicate a kind of communication process which takes about 20 seconds, I need

a kind of activity display which is controlled by a database field:

  • A animated gif will be shown until process terminated

    This can be controlled by php code and will be placed in Visual editor 'Header' (global to all forms)

    => This works OK
  • To update this regulary I need an autommatic page refresh every 5..10 seconds till the status

    in a database field changes again.

    How can this be done?

    a) I can do a HTML based refresh by editing the <HEAD>.... section manually

    but I cannot control this in runtime.

    <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=20064&image=1&table=forumtopics' class='bbc_emoticon' alt='B)' /> Would this be possible by JavaScript??

    (and controlled by echoing/omitting the reference to the java script)
    Best Regards
    ckranich

C
ckranich authorDevClub member 9/18/2012

Hi Again,
As far as i understand, what I want to implement is some kind of

'poor man's ajax' - When I understand ajax good enough, ajax should be plan B....
Findings so far:

  1. JS Refresh function can be included into js file located in <targetpath>/include/myfirst.js

function timedRefresh(timeoutPeriod) {

setTimeout("location.reload(true);",timeoutPeriod);

}


2) This js file is included to project in Visual Editor / Header (outside PHP agled braces ):

<script type="text/javascript" src="include/myfirst.js"></script>


3) In the JavaScript OnLoad event of all forms, the function is called

function OnPageLoad(pageid)

{

// this calls a function in myfirst.js (if existsts)

timedRefresh(5000);

}


Now I will have to look for a way to enable/disable this via PHP/database...
Kind Regards,
ckranich

C
ckranich authorDevClub member 9/18/2012

Hello again,
I solved it.

(At least it works for now, with some flicker...)

  1. Simply echoed the reference to the java script file only if the autorefresh on this page

    is wanted(if not echoed, eg missing in the page, the target function for the redirect call in the onLoad event is not found;

    this is really quick and DIRTY...)
    ... Design Edit/Header....

switch ($status)

{

case '1': // do autorefresh

echo '<img src="images/progress_bar2.gif">'; // show activity

echo 'Downlink...';

echo '<script type="text/javascript" src="include/myfirst.js"></script>';

break;

case '2': // no autorefresh

echo 'Downlink Finished';

break;



.......
2) After Record Updated fires a redirect back to the edit page

(A simple reload won't work nice as this re-POSTs )

header("Location:"."http://my_path_to_script/my_edit.php?editid1=1";);

exit();


Solved and closed. Another example that whatever you want - A solution might be not far away if you use php runner...

Thx Sergey!
Kind greetings,
ckranich