jeudi 23 juillet 2020

How can I send multiple HTTP requests to a URL using Axios and stop sending once I receive a response from one of the request?

I am new to javascript and trying to write a script that will send multiple HTTP requests to a web server using Axios. The server is designed in such a way that it will send response randomly to a request. Now, I want the script to stop sending the requests once it receives one response. The basic code which I could write yet is:

axios.get('http://localhost:8080/ubuntu_default.html', { withCredentials: true }).then(function (response) {
    document.body.innerHTML = generateSuccessHTMLOutput(response);
});

function generateSuccessHTMLOutput(response) {
    return response.data;
}

Assume this .js file will be present in the client's browser.




Aucun commentaire:

Enregistrer un commentaire