Search code examples
phphtmlpartial-page-refresh

Updating contents without refreshing?


I want to update a division of my webpage updated frequently. But the contents of the division is to be loaded from another file on the server which is unable to be accessed from the file. I have made the access for the first time through PHP on the server. When I'm updating the information, the javascript is on client-side and I'm unable to access it.Also, the meta tag refreshes the entire webpage. I just want to update the division

What are the ways to solve this problem?


Solution

  • You could do this with jQuery and AJAX

    like this:

    $.get('/route/to/file', { args }, function(data) {
       $('#some-container').html(data);
    });
    

    If you need it to be fully realtime, you could also use Socket.io:

    var ws = io( ... );
    ws.on('some.realtime.event', function(data) {
       $('#some-container').html(data);
    });