React
React
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
xhrCurrent = new XMLHttpRequest();
|
||||
url = 'http://localhost:8000/searches';
|
||||
xhrCurrent.open("POST", url, true);
|
||||
xhrCurrent.setRequestHeader('Access-Control-Allow-Methods', 'POST');
|
||||
xhrCurrent.setRequestHeader("Content-Type", "application/json");
|
||||
xhrCurrent.onerror = function () {
|
||||
alert("Fehler");
|
||||
}
|
||||
xhrCurrent.onreadystatechange = function () {
|
||||
if (xhrCurrent.readyState === 4 && xhrCurrent.status === 200) {
|
||||
var parent = document.getElementById("currentSearch");
|
||||
var child = parent.lastElementChild;
|
||||
while (child) {
|
||||
parent.removeChild(child);
|
||||
child = parent.lastElementChild;
|
||||
}
|
||||
var textField = document.createElement("p");
|
||||
var json = JSON.parse(xhrCurrent.response);
|
||||
var output = json.Search;
|
||||
textField.innerHTML = output;
|
||||
document.getElementById("currentSearch").appendChild(textField);
|
||||
}
|
||||
};
|
||||
|
||||
// Converting JSON data to string
|
||||
var data = JSON.stringify({ "Search": "current" });
|
||||
|
||||
// Sending data with the request
|
||||
xhrCurrent.send(data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user