50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
xhrDone = new XMLHttpRequest();
|
|
let url = 'http://localhost:8000/searches';
|
|
xhrDone.open("POST", url, true);
|
|
xhrDone.setRequestHeader('Access-Control-Allow-Methods', 'POST');
|
|
xhrDone.setRequestHeader("Content-Type", "application/json");
|
|
xhrDone.onerror = function () {
|
|
alert("Fehler");
|
|
}
|
|
xhrDone.onreadystatechange = function () {
|
|
if (xhrDone.readyState === 4 && xhrDone.status === 200) {
|
|
var parent = document.getElementById("doneSearches");
|
|
var child = parent.lastElementChild;
|
|
while (child) {
|
|
parent.removeChild(child);
|
|
child = parent.lastElementChild;
|
|
}
|
|
var resp = xhrDone.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 button = document.createElement("button");
|
|
var text = array[i];
|
|
button.innerText = text;
|
|
document.getElementById("doneSearches").appendChild(button);
|
|
button.onclick = function () {
|
|
window.sessionStorage.setItem("search", button.textContent);
|
|
location.href = "analyse.html";
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// Converting JSON data to string
|
|
var data = JSON.stringify({ "Search": "done" });
|
|
|
|
// Sending data with the request
|
|
xhrDone.send(data);
|
|
|
|
|