<html>
<head>
<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8">
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<form id="myForm">
<input id="username" type="hidden" value='wer43t' size="20"><br/><br/>
<input type="submit" id="btn" value="Отправить">
</form>
<div id="content"></div>
<script>
var interval;
function show(url) {
$.ajax({
type: "POST",
url: url,
data: "username=" + $("#username").val(),
dataType:"json",
success: function(data) {
//$("#content").html(html);
if (data.result == "error")
{
//alert ("Ошибка");
console.log(data);
setTimeout(function() {
clearInterval(interval);
}, 1000*30/2);
}else
{
console.log(data);
}
}
});
return false;
}
let $btn = $('.btn');
interval = setInterval(function() {
$('.btn').click(show("greetings.php"));
}, 3000);
</script>
</body>
</html>
<?php
$file = '1234_.txt';
if (!file_exists($file)){
$err = "error";
die(json_encode(array('result' => $err)));
}else
{
$err = "succes";
die(json_encode(array('result' => $err)));
}
?>
var interval;
function show(url) {
$.ajax({
type: "POST",
url: url,
data: "username=" + $("#username").val(),
dataType:"json",
success: function(data) {
if (data.result == "error") {
console.log(data);
setTimeout(function() {
clearInterval(interval);
// another request
$.ajax({
type: "POST",
url: "someurl",
dataType:"json",
success: function(data) {
// some actions
}
});
}, 1000*30/2);
} else {
console.log(data);
}
}
});
return false;
}