I have an function that sends AJAX request. It's working fine. In my getimage.php, I'm getting 1 row at a time base on ID from 0 to last row of ID. on return, var counter is set to ID value. It all works fine. Only I want the counter to reset back to 0 after my request reaches the last row of table so that my ajax request will run infinitely. Please anyone can show me a simple solution.
var lastsrc = null;
var counter = 0;
var delay = 0;
function changeimage(){
$.ajax({
url: 'getimage.php',
type: 'post',
data: {
iddata : counter
},
dataType: 'json',
success: function(data){
var id=data['id'];
var title=data['title'];
var path=data['path'];
var s_d=data['start_date'];
var e_d=data['expiration_date'];
var duration=data['duration'];
var site=data['site'];
alert(id);
counter = id
setTimeout(changeimage, 1000);
}
});
};
changeimage()