I have the following code that executes a query in DB with ajax. So when in success I add append instead of replaceWith, the function works perfectly and runs every 5 seconds, but when I insert replaceWith instead of append, the function only executes once and does not execute setimeout. >
PS: php variables appear so because the function is inside a php query.
function fetchdata". $row2['id'] ."(){
var dz='". $row2['id'] ."';
var dld='$jmmj';
$.ajax({
type: 'POST',
data: {dz: dz},
url: 'submit4.php',
success: function(datas){
if(datas!==''){
$('#message18w". $row2['id'] ."').replaceWith(datas);
}else{ $('#message18w". $row2['id'] ."').replaceWith('');}
setTimeout(fetchdata". $row2['id'] .",5000);
},
error:function(datas){
setTimeout(fetchdata". $row2['id'] .",5000);
},
complete:function(datas){
setTimeout(fetchdata". $row2['id'] .",5000);
}
});
}
$(document).ready(function(){
setTimeout(fetchdata". $row2['id'] .",5000);
});