app.js
const database = new Datastore('database.db');
database.loadDatabase();
app.get('/api', (request, response) => {
database.find({},(err,data)=> {
if(err){
response.end();
return;
}
response.json(data)
});
});
app.post('/api', (request, response) => {
const data = request.body;
database.insert(data);
response.json(data);
});
page1.js
function TableRow() {
let items = '1'
let domore = '2'
let cells = document.querySelectorAll('#recieve-info td');
cells.forEach(cell => cell.onclick = async function () {
let prevcell = cell.previousElementSibling;
if (prevcell) {
let data = {items, domore}
let options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:JSON.stringify(data)
};
const response = await fetch('/api',options);
const json = await response.json();
console.log(json);
}
});
}
I am trying to pass data from one page to another by onclick, like if i click on the first one which is 'Save1' I want to save data only in the first one. But now the data is saving on all three
page2.js
async function ParaG() {
const response = await fetch('/api');
const data = await response.json();
console.log(data);
for(item of data){
const para = document.querySelector('.Second-Para');
para.textContent += `${item.items}, ${item.domore}`
}
}
I have created a pop up modal for every button,like when I click on the first button I would like to have the data that has been saved in that button.
sorry for my English, I tried to explain what I could