I’m designing a system where a user will interact with my RESTful API through JS, and will replace the ts
html element with a different SVG if the returned answer is true
. If the API call returns false
, the JS should wait for 5 seconds, before retrying the API call. again, if the API call returns true
, the SVG will be changed, and the function will stop calling the API. How can I have the function “sleep” for 5 seconds before running again, and ending the function if the returned API call is true
?
Code:
async function getTransaction(){
var lookup = $("meta[name='lookup']").attr("content");
axios.get('http://127.0.0.1:5000/client_api/transaction_status/' + lookup)
.then(function (response) {
var tStat = response.data.transactionStatus;
console
if(tStat){
document.getElementById("ts").innerHTML = 'drawing the new svg and replacing the old one'
console.log('transaction_found')
}
else if(!tStat){
console.log("transaction not found")
}
else{
console.log("error")
}
});
}console.log("hello"); while(true){setTimeout(getTransaction,5000);}