I am a beginner in ajax/JS/jQuery. I have an ajax call that checks if a file is available on server. To accomplish this I use setInterval() and clearInterval(). I am having trouble in setting the display property to an html element upon successful ajax call. Any guidance is highly appreciated.
<html>
<head>
</head>
<body >
<div id="export-div" hidden>
Click Me
</div>
<script type="text/javascript">
function foo_func() {
$('#export-div').show(); //*****tried, but does not work*******
var foo = document.getElementById("export-div");
foo.style.display = "block"; // **********Does not work***************
alert(foo.innerHTML); //Alert box correctly pops up with text 'Click Me'
clearInterval(timerForLoadingResult); //I initially had this inside the ajax success/done function
}
</script>
<script type="text/javascript">
var timerForLoadingResult = setInterval(checkServerForFile,5000); //call the function in every 5 seconds and write ajax in that function.
function checkServerForFile() {
var chck = $.ajax("<?php echo "/Results/".$filename; ?>") //searches for a file on server
chck.success(function(){
alert( "Ajax call successful" ); //This alert box also pops up
foo_func();
});
};
</script>
</body>
</html>