0

I have a background process that is aggregating information for me, and I would like to make it so that the web page refreshes the containing div every 10 seconds. Unfortunatley, most of the articles I am coming across are for using JS and/or ajax with forms.

I'm trying to do something more along the lines of...

<script type="text/javascript"> 
    $(function() {
        check_articles("new_articles()", 10000);
    });

    function new_articles(){ 
        document.getElementById("articles").innerHTML="
        <?php  
            $this->select_articles();
        ?>"; 
    } 
</script> 

<div id="articles" onload="check_articles(); return false;">
    Article's contents.
</div> 

I really need to find the time to brush up on my JS... Anyway, the concept is there. The question is, is there a better (more effective / efficient) way to do this?

I've been up for nearly 24 hours so I'm going to play with this more tomorrow. Nonetheless, I look forward to hearing your guy's feedback and insight, as always.

Thanks.

4
  • Where is the check_articles function? How does it work? Commented Mar 1, 2014 at 14:33
  • You need to do this with Ajax. Commented Mar 1, 2014 at 14:35
  • @matewka: check_articles is the function referenced in the anonymous closure. Cleary, I don't write a lot of JS from scratch (I tried to make it so it didn't look like pseudo-code, lol). Anyway, I just got the Views straightened out enough to start playing around with this part, but I need to get some sleep before I dive deep. I'd appreciate any insight you might have. Commented Mar 1, 2014 at 14:44
  • Its not possible to call a php function from js. you need to make ajax call for that. Commented Mar 1, 2014 at 14:44

1 Answer 1

1

make an ajax call to the server script on regular interval (1000 milli seconds)

function callServer(){
 setInterval(function(){
   $.ajax({
     url: "server.php/select_articles",
     success:function(reponse) {
         $("#articles").html(response);
     }
   });
 },1000);
}

Happy Coding :)

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

1 Comment

Excellent, simple enough. I'll start playing around with it now. Thanks, dreamweiver.

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.