I am trying to get one API call to run after the other is finished, but for some reason the other function is never running. My code is as shows below:
console.log("the passwords are equal");
xhttp.addEventListener("load", handle_response);
xhttp.open("POST", "http://url/createPhysician/", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(JSON.stringify(body));
function handle_response() {
console.log("handle_response be running like a bosss!!")
var xhttp2 = new XMLHttpRequest();
console.log("handle_response got called");
var response = this.responseText;
console.log(response);
xhttp2.addEventListener("load", handle_response2);
//below gets the most recently added PhysicianID number for adding to the user tbl
xhttp2.open("GET", "http://url/getRecentPhysicianID/", true);
xhttp2.setRequestHeader("Content-type", "application/json");
xhttp2.send();
}
I cannot figure out if the function handle_response()
is even being called. When I check the console for the log activity, they pop up for a split second then disappear. However I can see in my database that the first API call for /createPhysician
is running properly
The code is being run by the following line:
document.getElementById("createUserButton").onclick = function ()
and the html for the button is as follows:
<div class="clearfix">
<button id = "createUserButton" type="submit">Create User</button>
</div>