using setInterval to check for a file I am waiting for
I am try to make a timer that periodically checks to see if a file has been written. Once the file exists I will read it and format output. This is what I am trying, but it seems to have created an infinite loop and I never get to success:
- <!DOCTYPE html>
<html>
<head>
<title>timer</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
var myVar=setInterval(function(){myTimer()},1000);
function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
$('#test-timer').html('<p>' + t +'</p>');
}
$('#time').click(function (){
$.ajax({
url:'result.xml',
cache:false,
error: function(){
var timer = setInterval(function(){$('#test-timer').html("still looking")},2000)
}, //end error function
success: function(){$('#test-timer').html("I found it!")}
})
}); //end click
}); //end ready
</script>
</head>
<body>
<section>
<h1>Show me the money</h1>
<div id="test-timer">
</div>
<br><button id="time">Start timing!</button>
</section>
</body>
</html>
The first function is irrelevant as I was just checking how setInterval worked. If this approach is not a good way to accomplish what i am trying for I am open to alternatives. Thanks for any assistance.