I am trying to call an API with XMLHttpRequest and then on success status I am trying to redirect it to the next page but redirection is working and the call is not working and If I remove the redirection the call works..
I am not sure if I cannot redirect while calling the API or I am doing something wrong so please check and advise
This is the code I am writing in the success of the AJAX call.
if (response.status === true) {
var api = "https://api-voice.solutionsinfini.com/v1/?api_key=****&method=dial.click2call&output=xml&caller=****&receiver=" + sessionStorage.fullNumber;
// Calling the API
var xhttp = new XMLHttpRequest();
xhttp.open("GET", api);
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById('myModalCallback').style.display = 'none';
window.location.href = "/anotherpage";
}
};
xhttp.send();
document.getElementById('myModalCallback').style.display = 'none';
}