I have following two files and want to get data from php and recieve it in javascript file.
1) PHP file:
<?php
$i;
for($i = 0; $i < 1000; $i++) {
echo $i;
}
?>
2) JavaScript file:
<script>
var j = -1;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
j = this.responseText;
}
};
xhttp.open("GET", "www.mywebsite.com/php_file.php", true);
while(j < 999) {
xhttp.send();
document.getElementById("demo").innerHTML = j;
}
</script>
Now, the problem is, when run my java script it return me the final value of 'i', but i want to retrieve every value of 'i' while it is in for-loop, like from 0 to 999.. but it return only when php file fully executes it self
echo $j;