-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatenkommunikation.txt
34 lines (27 loc) · 1.17 KB
/
Datenkommunikation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
JavaScript:
async function UserAction() {
var xhr = new XMLHttpRequest(); //invoke a new instance of the XMLHttpRequest
xhr.onload = success; // call success function if request is successful
xhr.onerror = error; // call error function if request failed
xhr.open('POST', 'http://localhost:8080/tickets/'); // open a GET request
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
vornameDesBesitzers:"Günther",
nachnameDesBesitzers:"Jauch",
startuhrzeit:"12:15:00",
kinosaalNummer:"2",
filmName:"Terminator7",
preis:"12.77",
status:"RESERVIERT"
})); // send the request to the server.
}
function success() {
var data = JSON.parse(this.responseText.toString()); //parse the string to JSON
console.log(data);
}
// function to handle error
function error(err) {
console.log('Request Failed');
}
HTML:
<button onclick="UserAction()">Test</button>