ajax呼び出しを行い、継続的に実行するJS関数が1つあります
function First(ServerId)
{
var CallServer = jQuery.ajax({
type: "POST",
url: "somefile.php",
dataType: "json",
success: function(response)
{
// do something here
First(response.ServerId);
}
}};
}
somefile.phpには60 秒のスリープ タイマーがあるため、ajax 呼び出しは 60 秒後に応答を返します。異なるサーバー ID が返されるたびに。
今、別の機能があり、このようなことをしたい
function Second()
{
/*
wait for 5 seconds to see if function First() has returned server id
if (ServerIdIsReturned)
{
i) abort CallServer
ii) make another Ajax call (CallServer2)
iii) after CallServer2 is done, call CallServer with the returned ServerId
}
else
{
i) abort CallServer
ii) make another Ajax call (CallServer2)
iii) after CallServer2 is done, call CallServer with the ServerId as 0
}
*/
}
適切に説明したかどうかはわかりませんが、Second()
関数First()
が新しいサーバー ID を返したかどうかをチェックインし、それに応じて先に進みたいと思います。setTimeout を使用して Second() 関数を分割する必要があると思いますが、よくわかりません。
どうすればこれを達成できますか?