I have an easy problem regarding the use of fetch in html files.
I've created an API in AWS Api Gateway that has a simple GET method: the GET method returs a json.
Now, if i access directly or using postman to the link of my method it works correctly, but when i try to use fetch something wrong happens and i see no results.
I search on the internet because i don't know neither javascript nor html, but i can't find how make it works correctly. For example what i'm trying to do in the code that follows is to put the json taken via GET into a label.
This is my html file:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>test.html</title>
</head>
<body>
<dl>
<dt>Page 1</dt>
<dd>Go to <a href="https://xxx.execute-api.eu-central-
1.amazonaws.com/prod/getcustomerdetailsbyemail/">link</a></dd>
</dl>
<p> <input name="Button" value="Click me" onclick="buttonClick()" type="button"> <input
name="Button2" value="Click me 2" formmethod="get" onclick="buttonClick2()" type="button">
</p>
<p> <input id="myText" name="Message" value="Insert text" type="text"></p>
<label for="myText" id="mylabel"></label>
<div id="myData"> </div>
<dl>
</dl>
<dl>
</dl>
<script type="text/javascript">
function buttonClick(){
alert(document.getElementById("myText").value);
}
</script>
<script type="text/javascript">
function buttonClick2(){
fetch("https://xxx.execute-api.eu-central-1.amazonaws.com/prod/getcustomerdetailsbyemail")
.then(response => {
document.getElementById("mylabel").value = response.json();
})
.catch(error => {
alert("Nope");
});
</script>
</body>
</html>
How can i put the json returned by the get call into a label?
I have another question: if i put console.log("message") in a script in an html file, what should i expect to happen when the script is run? (Spoiler: nothing happens, why?)
I apologize if I am ignoring something crucial, but I don't know where to start.
document.getElementById("mylabel").textContent = response.json();HTML labels dont have avalueproperty, but HTML input does