R
Railway15mo ago
ryanpzr

Fetch failed

Please help me with this problem guys! My website does not show the content that is in the database! Fetch: function carregarTodasBonecas() { // Solicita todas as bonecas ao servidor fetch('https://agulha-e-linha-production.up.railway.app/upload', { method: 'GET' // Especifica o método HTTP como GET }) .then(response => { if (response.ok) { return response.json(); } else { throw new Error('Erro ao buscar dados do servidor.'); } }) .then(data => { // Renderize as bonecas na tela data.forEach(boneca => { const novoItem = criarElementoBoneca(boneca); main.appendChild(novoItem); }); }) .catch(error => { console.error('Erro ao buscar dados:', error.message); }); } NodeJS: server.get('/upload', (req, res) => { // Consulta o banco de dados para obter todas as bonecas const sql = 'SELECT * FROM bonecas'; db.query(sql, (err, result) => { if (err) { console.error('Erro ao buscar bonecas no banco de dados:', err); return res.status(500).json({ error: 'Erro ao buscar bonecas' }); } else { // Retorna todas as bonecas encontradas no banco de dados return res.json(result); } }); });
2 Replies
Percy
Percy15mo ago
Please provide your project ID or reply with N/A. Thread will automatically be closed if no reply is received within 10 minutes. You can copy your project's id by pressing Ctrl/Cmd + K -> Copy Project ID.
Percy
Percy15mo ago
No project ID was provided. Closing thread.
Want results from more Discord servers?
Add your server