I have index.php file which is as following :
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="ajax.js"></script>
</head>
<body>
<div id="summary">The returned value will go here</div>
</body>
</html>
The content of ajax.js which is supposed to keep calling/invoking function.php until function.php returns '1' :
function check(){
return $.ajax({
url: 'function.php',
type:'POST',
success: function(response){
if(response == '1'){
$('#summary').html(response);
}else{
check();
}
},
failure: function(jqXHR, textStatus, errorThrown){
console.log(textStatus);
}
});
}
check();
And Finally function.php :
<?php
echo "1";
?>
I expected that function.php would only be invoked once since function.php returns "1". However it keeps calling function.php endlessly.
Can someone point me out how to get this working properly?
responsein the success handler== 1instead of== '1'.if(response.trim() == '1'){and addalert(':' + response + ':')before theifstmt