im having a problem, I cant seem to stop the timer... in fact it speeds up!
var number = 0;
var timer;
function get_data( url ){
number++;
$('#requests').html( number );
$.ajax({
type: 'POST', url: './includes/ajaxGetData.php', data: 'url=' + encodeURIComponent(url), cache: false, timeout: 10000,
error : function(){
timer = window.setTimeout( get_data( url ), 2000 );
},
success: function(html){
if( html.substr(0,12) == '<!-- die -->' ) {
$("#result").html('<p>Complete...</p>' + html );
$('#requests').html('');
clearTimeout(timer);
}else{
$("#result").html(html);
timer = window.setTimeout( get_data( url ), 2000 );
}
}
});
}
get_data( 'http://example.com' );
can anyone see where im going wrong?