Hands-On Artificial Intelligence on Amazon Web Services by Subhashini Tripuraneni

Hands-On Artificial Intelligence on Amazon Web Services by Subhashini Tripuraneni

Author:Subhashini Tripuraneni
Language: eng
Format: epub, mobi
Tags: COM004000 - COMPUTERS / Intelligence (AI) and Semantics, COM048000 - COMPUTERS / Systems Architecture / Distributed Systems and Computing, COM037000 - COMPUTERS / Machine Theory
Publisher: Packt Publishing
Published: 2019-10-04T12:11:27+00:00


function saveContact() {

let contactInfo = {};

let fields = ["name", "title", "email", "phone", "organization", "address", "city", "state", "zip"];

fields.map(function(field) {

let element = document.getElementById(field);

if (element && element.value) {

contactInfo[field] = element.value;

}

return field;

});

let imageElem = document.getElementById("image");

contactInfo["image"] = imageElem.src;

// make server call to save contact

return fetch(serverUrl + "/contacts", {

method: "POST",

headers: {

'Accept': 'application/json',

'Content-Type': 'application/json'

},

body: JSON.stringify(contactInfo)

}).then(response => {

if (response.ok) {

clearContact();

return response.json();

} else {

throw new HttpError(response);

}

})

}

In the preceding code snippet, the following things occur:

The saveContact() function gets a value from every input field and then creates the contactInfo data structure. This function then sends the data in contactInfo to the server for persistence.

If the response from the server is ok, it means the contact has been saved.

Then, this function calls the clearContact() function to clear the values of the input fields and the image display.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.