How to complete ajax and call another funzio?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
8 views
Good afternoon. I have a form which is sent ajax'the php script. If the script generates an error for a certain time interval and the ajax call is terminated. I need to do so that after the interval was called by another php script. Which was recorded in the database that there is no such file. And return a message to the user.


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);


greetings.php
<?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))); } ?>
by | 8 views

1 Answer

0 like 0 dislike
Can not grasp, why then do interval. But not the essence. Response to mine just after clearInterval to take and make another request, though the same $.ajax.

Example:
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; }


It would be better if it has anything to divide and decorate than cabecou noodles continue to climb.
Because of the range can be a problem - a timeout need to ask once, and clear in case of success. In General, there are many "but".
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Apr 28, 2019 by romashkoaleksandr
0 like 0 dislike
5 answers
0 like 0 dislike
5 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,456 users