1

i would like to know what its a good way of auto load new content without page refresh. for example, previously in twitter trending, when someone posted related trending contents, it will auto load the newly submitted content without page load.

i tried a few methods, for example (pull methods), in my javascript i would set intervals to load frm sql query:

var auto_refresh = setInterval(function () {
        $('#myLinks').load('http://domain.com/link/loadlatestnews').fadeIn(2000);
    }, 400); // refresh every 400 milliseconds

but is this a good idea because it requires the client to constantly trying to load from sql every 400 milliseconds.

is it possible to have push methods whereby if there's a new content in mysql, set a event callback??

3 Answers 3

2

what you are doing right now is a good idea, but don't poll your server every 400 MS if it is not much powerful. Also you should send a last end-date to the server on each request so it will load only the content which came after that date, and return the new last date each time on every request. that way you can check if the server has new records and fire a function if it does so.

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

3 Comments

hmm thats a good way to do.. so that i wont consume so much resources. i realise that too much mysql loading cause the cpu load to be high
hi, i have a Q. what if there r 2 records with the same timestamp.. how do i get the record then?? my sql query is: SELECT * FROM records WHERE 1 AND dateTimeSubmitted >1330754710 ORDER BY dateTimeSubmitted LIMIT 1
both of them will be returned, automatically.
0

You can auto refresh in this way

<script type="text/javascript" src="../js/jquery.min.js"></script>
        <script type="text/javascript">
            // setTimeout(function(){ window.location.reload(); }, 2000);

                $.ajax({
                 success:function(){
                     setTimeout(function(){ window.location.reload(); }, 2000)
                 }   
                });

        </script>

3 Comments

he is not asking for page reload he is asking for a method to refresh the content on the page via ajax every x minutes
yes i have you used ajax only for page refresh,,run on your system
its not page reload ajax makes this as refresh ,,
0

It depends. Have You access to Your server software or not. And if You are willing to configure it or not.

What You need is comet server: http://en.wikipedia.org/wiki/Comet_(programming)

But if Your site is not big You just can use timing polling technique as You are using now. Just make intervals longer. 400 ms is way to short. Also try to optimize Your SQL as Shaheer suggested.

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.