Skip to content
Snippets Groups Projects
Commit 3646f891 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #49993 by Sid_M: fixed two minor problems with HTTPGet().

1) There is a race condition created by calling send() before setting the callback function. Admittedly, this race shouldn't be lost, but it's not good practice to bet on winning races in code.

2) Line 55 is redundant. Since the value of bAsync is based on the non/existence of callbackFunction, there is no need to check both variables later.
parent 55eec8f6
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -48,15 +48,14 @@ function HTTPGet(uri, callbackFunction, callbackParameter) {
if (!callbackFunction) {
bAsync = false;
}
xmlHttp.open('GET', uri, bAsync);
xmlHttp.send(null);
if (bAsync) {
if (callbackFunction) {
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
}
}
return xmlHttp;
......@@ -93,11 +92,9 @@ function HTTPPost(uri, callbackFunction, callbackParameter, object) {
xmlHttp.send(toSend);
if (bAsync) {
if (callbackFunction) {
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter);
}
}
return xmlHttp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment