Search code examples
asynchronousrefreshreload

Page auto reload without refresh


Hi I want to know How to make the page reload asynchronous, for example if someone has received a message , the last message will appear without refreshing the page. just like facebook. thank you.


Solution

  • You would have to use something like JQuery & Javascript to poll the server for changes and display them on the page in a div.

    setInterval('someFunc()', 1000)
    
    function someFunc()
    {
    
     $.ajax({
                async: true,
                type: "GET",
                url: "www.domain.com/url",
                data: data,
                success: function (html) {
                    $("#myDiv").html(html);                
                }  
            });
    
    }
    

    This will update the div with ID myDiv every second with the data from www.domain.com/url passing in data is a param (you will have to define 'data')