I want to nest an AJAX request in a jQuery so I can put a time interval of 5 seconds.
The AJAX request does what it’s supposed to do, but from the moment I try to nest it I keep getting the message:
"jQuery.ajax is not a function"
How do I fix this – where do I make a mistake?
This is the (working) ajax request:
jQuery.ajax({
url: "check.php",
success: function(result) {
var html = jQuery('<div>').html(result);
var x = (html.find("div#a").html());
console.log(x);
}
});
this the nested code – which results in a jQuery.ajax is not a function error:
<script type="text/javascript">
var row1 = "<?php echo $row_cnt; ?>";
var interval = 1000; // 1000 = 1 second, 3000 = 3 seconds
function doAjax() {
jQuery.ajax({
url: "check.php",
success: function(result) {
var html = jQuery('<div>').html(result);
var x = (html.find("div#a").html());
console.log(x);
}
});
}
setInterval(doAjax, interval);
</script>
When I google the problem, I get a lot of answers about the "slim – jquery libary", but I use this one:
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
2
Answers
Thanks for your help! The problem was that lower down in the code I was still getting the slim libary - this had eluded my attention.
The problem is solved.
move this
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
up script with interval