I want to refresh my div with PHP code in div tag but it’s don’t work. console said:
Uncaught TypeError: $(…).load is not a function
at doRefresh
JavaScript
x
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>
</head>
<body>
<div id="actu">
<?php include 'process.php'; ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
function doRefresh(){
$("#actu").load("process.php");
}
$(function() {
setInterval(doRefresh, 2000);
});
});
</script>
</body>
</html>
EDIT
OP has updated code based on answer and comments.
Advertisement
Answer
Include your code in a document ready handler to ensure the script will run once the page loads:
JavaScript
<script type="text/javascript">
$( document ).ready(function() {
function doRefresh(){
$("#actu").load("process.php");
}
setInterval(doRefresh, 5000);
});
</script>
In addition, remove one of the jQuery library requests as this may cause problems. You also have an extra </script>
tag which should be removed.
You do not need the second document handler, but it should not hurt anything. I have removed iy here.