47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
xhrPending = new XMLHttpRequest();
|
|
url = 'http://localhost:8000/searches';
|
|
xhrPending.open("POST", url, true);
|
|
xhrPending.setRequestHeader('Access-Control-Allow-Methods', 'POST');
|
|
xhrPending.setRequestHeader("Content-Type", "application/json");
|
|
xhrPending.onerror = function () {
|
|
alert("Fehler");
|
|
}
|
|
xhrPending.onreadystatechange = function () {
|
|
if (xhrPending.readyState === 4 && xhrPending.status === 200) {
|
|
var parent = document.getElementById("pendingSearch");
|
|
var child = parent.lastElementChild;
|
|
while (child) {
|
|
parent.removeChild(child);
|
|
child = parent.lastElementChild;
|
|
}
|
|
var resp = xhrPending.response;
|
|
var json = JSON.parse(resp);
|
|
var output = json.Search;
|
|
var array = [];
|
|
if (output == "") {
|
|
return;
|
|
}
|
|
while (output.indexOf(';') != -1) {
|
|
var a = output.substring(0, output.indexOf(";") - 1);
|
|
output = output.substring(output.indexOf(";") + 1);
|
|
array.push(a.trim());
|
|
}
|
|
array.push(output.trim());
|
|
for (var i = 0; i < array.length; i++) {
|
|
var textField = document.createElement("p");
|
|
var text = array[i];
|
|
textField.innerText = text;
|
|
document.getElementById("pendingSearch").appendChild(textField);
|
|
|
|
}
|
|
}
|
|
};
|
|
|
|
// Converting JSON data to string
|
|
var data = JSON.stringify({ "Search": "pending" });
|
|
|
|
// Sending data with the request
|
|
xhrPending.send(data);
|
|
|
|
|