Hello guys i am trying to show real time loop data. using AJAX i want when AJAX run its get real time number update from action page loop.
$.ajax({
url: "number.php",
type: "POST",
data: {
name: name
},
cache: false,
success: function() {
/// some code to get result
}
and loop page number.php
<?php
$id =$_POST['id'];
while(true) // no matter
{
echo '<script>
int i = 0;
int ii += i;
print(i); // i want to shoe this value
i++;
</script>'
}
What you are trying to do can be achieved by using web-sockets or http-long-polling
I would suggest that you use websockets, using Ratchet, Ratchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over Web-sockets.
Using ajax is kinda not a good idea, because you have to send request to the server after every X seconds, to fetch data even if there are no changes in the server. doing this is more like you are DDos attacking your own server without knowing that.
But if you insist on ajax you would run a function that will send a request to the php script every x seconds, here's how you would do that with Ajax.
$('document').ready(function () {
setInterval(function () {getRealData()}, 1000);//request every x seconds
});
function getRealData() {
$.ajax({
url: "number.php",
type: "POST",
data: {
name: name
},
cache: false,
success: function () {
/// some code to get result
}
}
}
NB: AS I have said above better have a look into websockets.