I want to show data as soon as new data is entered, but I do not want that user always refreshes the page to see new data.
Asked
Active
Viewed 1,764 times
-5
-
2Does it really need to be continuous? Would it be sufficient to check for new data every 10 seconds or so using an AJAX request? What have you tried and what specifically goes wrong? – showdev Aug 15 '16 at 17:27
-
2Look into using web sockets. Ideally, **don't** poll (for instance, every 10 seconds as @showdev mentioned) if you have any choice (and you almost certainly do). socket.io is one lib you might look at which manages web sockets, with fallback for obsolete browsers without support for them. – T.J. Crowder Aug 15 '16 at 17:27
1 Answers
0
You can use a php script to call ajax url like
$(function(){
getAjaxRequest();
});
function getAjaxRequest(){
$.ajax({
url:"someurl.php",
data:{data:"data"},
success:function(result){
//result retrieval queries
//and
setTimeout(getAjaxRequest,1000); //call the same function every 1s.
},
error:function(err){
//error handler
}
});
}

Jitendra Patwa
- 170
- 12