Dumb question. I have two pages, "Index.html" and "func.php" in the same directory. I'm trying to call the PHP page every 2 seconds, get it's ECHO and display it on a paragraph element. No error, but the paragraph text simply won't change (and stay 0), here's the code:
Index.html
<html>
<body>
<?php
int cont = 0;
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
<script>
req()
{
$.ajax({url: "func.php"}, success: function(data) {
document.getElementById("p1").innerHTML = data;
});
setInterval(req(), 2000);
};
$('document').ready(function(){
setInterval(req(), 2000);
});
</script>
<p id="p1">0</p>
</body>
func.php
<?php
cont++;
echo cont;
?>
Any help?
$. You are never initializing the variable$contanywhere too but try to increment it. EDIT: I see you doint cont = 0;on the top in index.html but that will never work, learn the basics of php.