I have a review popup which when closed using the x button should close itself and then call a XMLHttpRequest to call a web service for updating some feedback info.
The issue I have is that when the button is clicked the window popup does not close instantly but seems to wait for the XMLHttpRequest to return 200. Is this due to "EventListener" behaviour or the "XMLHttpRequest"?
I should probably mention that I am specifically making XMLHttpRequest synchronous via the "false" param in xmlHttp.open( "GET", URL, false );
as this seems to be required as when the request is async eg: xmlHttp.open( "GET", URL, true);
the if (xmlHttp.status === 200)
doesn't run and is required for setting a global variable needed down the line.
I have added my code below.
Is there a way for my feedbackPopup()
function to close the popup window without waiting for the web service 200? I need the window close to be instant.
Sorry if im making a silly mistake somewhere, still learning.
Thank you in advance for any help.
//used for running closeFeedback Logic
var close = document.getElementById('closeOverlay');
close.addEventListener('click', closeFeedback);
function updateFeedback(a, b, c){
const host = window.location.host;
let URL = 'someURL${a}${b}${c}'
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", URL, false ); // false for synchronous request
xmlHttp.send( null );
if (xmlHttp.status === 200){
// this is not set for future use if line 14 is set to true
SomeGlobal = b;
}else{
console.log("xmlHttp.status","",xmlHttp.status)
}
}
//this is used for both opening and closing the popup which is why the conditional operator is used
function feedbackPopup() {
el = document.getElementById("feedback");
el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}
//should close feedback and call web service function
function closeFeedback(){
//ISSUE : this closeFeedbackWindow should close the window before updateFeedback runs and should not wait for updateFeedback to retunr 200???
feedbackPopup();
updateFeedback(a, b, c);
...
//More logic here which uses the SomeGlobal variable set in updateFeedback
}