Question: How to send a fetch request to database , trying to send a request but getting an error Homescript.js console.log(script connected.); var heart_status = 0;

How to send a fetch request to database , trying to send a request but getting an error

Homescript.js

console.log("script connected.");

var heart_status = 0; // 0 is empty and 1 is filled

var date = new Date();

var year = date.getFullYear();

var month = date.getMonth();

var day = date.getDate();

const previousDate = (year, month, day) => {

if (day - 1

month -= 1;

} else {

day -= 1;

}

return [year, month, day];

};

const dateToString = (year, month, day) =>

String(year) + "-" + String(month) + "-" + String(day);

document.getElementById("heart-button").addEventListener("click", () => {

let heart = document.getElementById("heart-button");

if (heart_status == 0) {

heart.src = "static/heart-filled.png";

heart_status = 1;

// TODO: update the database and mark this image as a favorite image.

fetch('/add', {

method: 'POST',

body: JSON.stringify(heart),

headers: {

'Content-type': 'application/json; charset=UTF-8'

}

})

.then(response => response.json())

.then(json => {

console.log(json);

});

} else {

heart_status = 0;

heart.src = "static/heart.png";

// TODO: update the database and un-mark this image as a favorite image.

}

});

document.getElementById("next-button").addEventListener("click", () => {

document.getElementById("heart-button").src = "static/heart.png";

heart_status = 0;

[year, month, day] = previousDate(year, month, day);

fetch(

"https://api.nasa.gov/planetary/apod?api_key=xRSoeMQHQJ5IiKwhHnOYfppEE05ADhjDFg18Qdwx&date=" +

dateToString(year, month, day)

)

.then((r) => r.json())

.then((r) => {

console.log("current APOD data:");

console.log(r);

document.getElementById("apod-date").innerHTML = r.date;

document.getElementById("apod-image").src = r.url;

document.getElementById("apod-title").innerHTML = r.title;

document.getElementById("apod-p").innerHTML = r.explanation;

});

});

How to send a fetch request to database , trying to send

2021-11-28 0 Welcome Elements >> + 1 16 .

flex sa

Astronom Picture of the Day

html body main Styles Computed Layout Event Listeners DOM Breakpoints Properties Filter :hov .cls to style.css: element.style { } main display: flex; 999 flex-direction: column; align-items: center; margin: auto; padding: 0px; width: 800px; style.css: Margin: 8px; padding: Opx; text-decoration:none; box-shadow: none; outline: none; Console Issues + A High cliff on Comet Churyumov-Gerasimenko This high cliff occurs not on a planet, not on a moon, but on a comet. It was discovered to be part of the dark nucleus of Comet Churyumov-Gerasimenko (CG) by Rosetta, a robotic spacecraft launched by ESA that rendezvoused with the Sun-orbiting comet in 2014. The ragged cliff, as featured here, was imaged by Rosetta in 2014. Although towering about one kilometer high, the low surface gravity of Comet CG would likely make it an accessible climb -- and even a jump from the cliff survivable. At the foot of the cliff is relatively smooth terrain dotted with boulders as large as 20 meters across. Data from Rosetta indicates that the ice in Comet CG has a significantly different deuterium fraction -- and hence likely a different origin -- than the water in Earth's oceans. Rosetta ended its mission with a controlled impact onto Comet CG in 2016. Comet CG has just completed another close approach to Earth and remains visible through a small telescope o top O Filter Default levels 16 planet just a... Lways, to see its moons will require a telescope.", media type: 'video', service_version: 'vi', title: 'In Motion: Uranus and Moon s', A Cross-Origin Read Blocking (CORB) blocked cross-origin response https://ww w.youtube.com/embed/VYWjxvm14Pk?rel=0 with MIME type text/html. See http s://www.chromestatus.com/feature/5629799824032768 for more details. Uncaught ReferenceError: url is not defined homescript.js:27 at HTMLImageElement. homescript.js:2 7) current APOD data: homescript.js:56 homescript.js:57 copyright: 'Jonathan Lodge', date: '2021-11-29', explanation: 'What cre ated the strange spiral structure on the ... Lumination by Light reflecte d from nearby stars.', hdurl: 'https://apod.nasa.gov/apod/image/2111/LLP egasi_HubbleLodge_1926.jpg', media_type: 'image', -} current APOD data: homescript.js:56 homescript.js:57 {date: 2021-11-28', explanation: 'This high cliff occurs not on a plane t, not on a m..th and remains visible through a small telescope.', hdurl: "https://apod.nasa.gov/apod/image/2111/cometcliffs_RosettaAtkinson_960.j pg', media_type: 'image', service_version: 'vi', ...) Uncaught ReferenceError: url is not defined indowhomescript.js:27 Q at HTMLImageElement. anonymous homescript.is:2 ivate Windows Next 2021-11-28 0 Welcome Elements >> + 1 16 .
flex sa

Astronom Picture of the Day

html body main Styles Computed Layout Event Listeners DOM Breakpoints Properties Filter :hov .cls to style.css: element.style { } main display: flex; 999 flex-direction: column; align-items: center; margin: auto; padding: 0px; width: 800px; style.css: Margin: 8px; padding: Opx; text-decoration:none; box-shadow: none; outline: none; Console Issues + A High cliff on Comet Churyumov-Gerasimenko This high cliff occurs not on a planet, not on a moon, but on a comet. It was discovered to be part of the dark nucleus of Comet Churyumov-Gerasimenko (CG) by Rosetta, a robotic spacecraft launched by ESA that rendezvoused with the Sun-orbiting comet in 2014. The ragged cliff, as featured here, was imaged by Rosetta in 2014. Although towering about one kilometer high, the low surface gravity of Comet CG would likely make it an accessible climb -- and even a jump from the cliff survivable. At the foot of the cliff is relatively smooth terrain dotted with boulders as large as 20 meters across. Data from Rosetta indicates that the ice in Comet CG has a significantly different deuterium fraction -- and hence likely a different origin -- than the water in Earth's oceans. Rosetta ended its mission with a controlled impact onto Comet CG in 2016. Comet CG has just completed another close approach to Earth and remains visible through a small telescope o top O Filter Default levels 16 planet just a... Lways, to see its moons will require a telescope.", media type: 'video', service_version: 'vi', title: 'In Motion: Uranus and Moon s', A Cross-Origin Read Blocking (CORB) blocked cross-origin response https://ww w.youtube.com/embed/VYWjxvm14Pk?rel=0 with MIME type text/html. See http s://www.chromestatus.com/feature/5629799824032768 for more details. Uncaught ReferenceError: url is not defined homescript.js:27 at HTMLImageElement. homescript.js:2 7) current APOD data: homescript.js:56 homescript.js:57 copyright: 'Jonathan Lodge', date: '2021-11-29', explanation: 'What cre ated the strange spiral structure on the ... Lumination by Light reflecte d from nearby stars.', hdurl: 'https://apod.nasa.gov/apod/image/2111/LLP egasi_HubbleLodge_1926.jpg', media_type: 'image', -} current APOD data: homescript.js:56 homescript.js:57 {date: 2021-11-28', explanation: 'This high cliff occurs not on a plane t, not on a m..th and remains visible through a small telescope.', hdurl: "https://apod.nasa.gov/apod/image/2111/cometcliffs_RosettaAtkinson_960.j pg', media_type: 'image', service_version: 'vi', ...) Uncaught ReferenceError: url is not defined indowhomescript.js:27 Q at HTMLImageElement. anonymous homescript.is:2 ivate Windows Next

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!