Replace custom httpGet() with $.ajax()" (#1371)

Signed-off-by: Paul Mannarino <paul.mannarino@gmail.com>
This commit is contained in:
Paul Mannarino
2020-05-25 14:59:18 -04:00
committed by GitHub
parent c86515e028
commit 256aff73a6
2 changed files with 22 additions and 60 deletions

View File

@@ -5,8 +5,6 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
/* global ActiveXObject: false */
var exact = "";
function quietfilter(ta, data) {
@@ -21,33 +19,6 @@ function quietfilter(ta, data) {
}
}
// Credit: http://stackoverflow.com/a/10642418/2087442
function httpGet(ta, quiet, theUrl) {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
ta.show();
ta.empty();
if (!quiet) {
ta.append(xmlhttp.responseText);
} else {
quietfilter(ta, xmlhttp.responseText);
}
}
};
xmlhttp.open("GET", theUrl, false);
xmlhttp.send();
}
function eventsource() {
var ta = $("#output");
var domain = $("#domain").val().trim();
@@ -65,11 +36,19 @@ function eventsource() {
// IE does not support EventSource - load whole content at once
if (typeof EventSource !== "function") {
httpGet(
ta,
quiet,
"scripts/pi-hole/php/queryads.php?domain=" + domain.toLowerCase() + exact + "&IE"
);
$.ajax({
method: "GET",
url: "scripts/pi-hole/php/queryads.php?domain=" + domain.toLowerCase() + exact + "&IE",
async: false
}).done(function (data) {
ta.show();
ta.empty();
if (!quiet) {
ta.append(data);
} else {
quietfilter(ta, data);
}
});
return;
}