Skip to content

Commit

Permalink
Replace custom httpGet() with $.ajax()" (#1371)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Mannarino <paul.mannarino@gmail.com>
  • Loading branch information
paul-man authored May 25, 2020
1 parent c86515e commit 256aff7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 60 deletions.
35 changes: 9 additions & 26 deletions scripts/pi-hole/js/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +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 */

// Credit: http://stackoverflow.com/a/10642418/2087442
function httpGet(ta, 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();
ta.append(xmlhttp.responseText);
}
};

xmlhttp.open("GET", theUrl, false);
xmlhttp.send();
}

function eventsource() {
var ta = $("#output");
var upload = $("#upload");
Expand All @@ -42,7 +17,15 @@ function eventsource() {

// IE does not support EventSource - load whole content at once
if (typeof EventSource !== "function") {
httpGet(ta, "scripts/pi-hole/php/debug.php?IE&token=" + token + "&" + checked);
$.ajax({
method: "GET",
url: "scripts/pi-hole/php/debug.php?IE&token=" + token + "&" + checked,
async: false
}).done(function (data) {
ta.show();
ta.empty();
ta.append(data);
});
return;
}

Expand Down
47 changes: 13 additions & 34 deletions scripts/pi-hole/js/queryads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down

0 comments on commit 256aff7

Please sign in to comment.