Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // method -> "GET"
- function Event_GET_Function() {
- fetch(baseUrl)
- .then((response) => response.json())
- .then((infoFromServer) => {
- for (let row in infoFromServer) {
- console.log(infoFromServer[row]);
- // pick data from array of objects for exmpl:
- let name = infoFromServer[row]['name'];
- let age = infoFromServer[row]['age'];
- let id = infoFromServer[row]['_id'];
- }
- });
- }
- // method -> "POST"
- function EventPOST_Function() {
- let dataObj = {
- 'student': student,
- 'age': age,
- };
- const headers = { method: 'POST', body: JSON.stringify(dataObj) };
- fetch(someUrl, headers)
- .then(() => someFunc());
- }
- // method -> "PATCH"
- function EventUPDATE_Function(event) {
- let id = event.target.parentNode.id; // Locate the "ID".
- let patchUrl = baseUrl + `${id}`;
- const headers = { method: 'PATCH', body: JSON.stringify({ name: newName }) };
- fetch(patchUrl, headers)
- .then(() => someFunc());
- }
- // method -> "DELETE"
- function EventDELETE_Function(event) {
- let id = event.target.parentNode.id; // Locate the "ID".
- let delUrl = baseUrl + `${id}`;
- const headers = { method: 'DELETE', };
- fetch(delUrl, headers)
- .then(() => someFunc());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement