-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostmessage.js
More file actions
25 lines (23 loc) · 868 Bytes
/
Copy pathpostmessage.js
File metadata and controls
25 lines (23 loc) · 868 Bytes
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
const uriMessage = 'https://5cd15d84d4a78300147be92e.mockapi.io/Message';
// Det vi skriver i textrutan hamnar i variabeln 'textInput'
function sendMessage() {
const textInput1 = document.getElementById('Message').value;
var data = { Message: textInput1 }
fetch(uriMessage,
{
// Nytt!
method: "POST", // *GET, POST, PUT, DELETE, etc
headers:
{
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(res => res.json())
.then(res => console.log(res))
// Eftersom MockAPI har en liten fördröjning så låter vi sidan uppdateras först efter
// en halv sekund.
setTimeout(() => {
loadMessage();
}, 1000);
}