1

I have php code like this :

<div>
<?php if($link AND $access AND !$timer_expired): ?>
<font color="green">Status: Unlocked - You have successfully unlocked "<?php echo htmlspecialchars($link['link_title']);?>", the website is listed below.</font>
<?php else:?>
<font color="red"> Status : Locked - To Unlock "<?php echo htmlspecialchars($link['link_title']);?>" Please Complete the Survey.</font>
<?php endif;?> 
</div>

I need to let it reload it self until the status be "Unlocked" then stop load

There is many of posts talking about reload php file..but i don't need that..i just want to reload php code

Any idea please ?

6
  • 1
    You just have to make an ajax call (in javascript) to another PHP script that will return the new value, an then, refresh your DOM in consequence Commented Mar 29, 2013 at 5:19
  • I answered a very similar question earlier today, maybe you could get some ideas from that stackoverflow.com/questions/15694792/… Commented Mar 29, 2013 at 5:20
  • @MatRt Please do you have any links for examples ? thank you. Commented Mar 29, 2013 at 5:25
  • can you use script for this? Commented Mar 29, 2013 at 5:27
  • @thumbernirmal i'm sorry i didn't understand your Q Commented Mar 29, 2013 at 5:33

3 Answers 3

1

First of all, if it is PHP page, you'd better to control status on the PHP side. Be independent of client-side. For "Locked" status page set the HTML meta header:

<meta http-equiv="refresh" content="5">

For "Unlocked" status do nothing.

That's all!

Sign up to request clarification or add additional context in comments.

2 Comments

I think, It have all php code suitable for views part. Condition checking for selctive html rendering is ok on views. Even he is using if/else statement colon form which is more suitable on views instead of pure PHP code.
I'm sorry..this is the baddest solution...i can't reload the full page..i just need to reload this part..thanks
0

It's not totally clear what you're asking, but you need to keep in mind that PHP code is executed on the server. AJAX is executed in the client's browser. So, the way to achieve what you want is to use AJAX to continuously reload the HTML in the client's browser, which you would request from a PHP script on the server.

HTML:

<div id="myDiv">AJAX response will load here</div>

Javascript:

function loadPage(your_page)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
         // This javascript executes when you receive the HTML from your AJAX request
        return xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET",your_page,true);
    xmlhttp.send();

}

var repeat = window.setInterval(checkResponse,3000);

function checkResponse()
{
   var response = loadPage('your_php_script.php');
   if(response.indexOf('Unlocked') !== -1)
       window.clearInterval(repeat);
}

1 Comment

Just to note: XMLHttpRequest does not properly work in IE7 (cannot require local file) and thus old ActiveX should be used instead
0

you want to use this function and call ajax like this.

<script type="text/javascript">

 jQuery(document).ready(function() {

  setInterval(function(){

   jQuery("#divid").load('http://example.php',
    function(response, status, xhr) {

        if (status == "error") {
        jQuery("#divid").html(msg + xhr.status + " " + xhr.statusText);
        }
    });
  }, 500);

 });
</script>

You also apply condition to check response is 'Locked' or 'Unlocked'.

Hope it helps to you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.