Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;

});

});

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

How prepared was the organization for the new business strategy?

Answered: 1 week ago