3 글 보임 - 1 에서 3 까지 (총 3 중에서)
-
글쓴이글
-
2022년 7월 23일 18:28 #39305
이한준참가자코딩애플님 버전과 달라서그런지 어디서 부터 잘못된건지 어렵습니다. server.js
list.ejs
콘솔창에 이러한 버그가 뜹니다.
그외에도 스크립트를 가져오는 주소가 잘못된건지 삭제요청이 제대로 안됩니다 혹시몰라 sever.js 전문을 올려보겠습니다
const express = require('express') const app = express(); const bodyParser= require('body-parser') app.use(bodyParser.urlencoded({extended: true})) app.use(express.urlencoded({ extended: true })) const MongoClient = require('mongodb').MongoClient app.set('view engine', 'ejs');
var db; MongoClient.connect('mongodb+srv://leeoujin:gkswns7777@cluster0.jziwvjp.mongodb.net/?retryWrites=true&w=majority',function(에러,client){
if(에러) return console.log(에러)
db = client.db('todoapp'); app.listen(8080,function(){ console.log('listening on 8080') }); });
app.get('/',function(요청, 응답){
응답.sendFile(__dirname + '/index.html') });
app.get('/write',function(요청, 응답){
응답.sendFile(__dirname + '/write.html') });
app.post('/add', function (요청, 응답) { db.collection('counter').findOne({name : '게시물갯수'}, function(에러, 결과){ var 총게시물갯수 = 결과.totalPost db.collection('post').insertOne({ _id : 총게시물갯수 + 1, 제목 : 요청.body.title, 날짜 : 요청.body.date }, function (에러, 결과) { db.collection('counter').updateOne({name:'게시물갯수'},{ $inc: {totalPost:1} },function(에러, 결과){ if(에러){return console.log(에러)} 응답.send('전송완료'); }) }) }) }) app.get('/list',function(요청,응답){
db.collection('post').find().toArray(function(에러,결과){ console.log(결과); 응답.render('list.ejs',{ posts : 결과}); }); }); app.delete('/delete', function(요청, 응답){ console.log(요청.body); 요청.body._id = parseInt(요청.body._id); db.collection('post').deleteOne(요청.body, function(에러, 결과){ console.log('삭제완료'); 응답.status(200).send({ message : '성공했습니다'}); }) });
app.get('/detail/:id', function(요청, 응답){ db.collection('post').findOne({ _id : parseInt(요청.params.id) }, function(에러, 결과){ 응답.render('detail.ejs', {data : 결과} ) }) }); detail/1 이렇게 따로 페이지는 잘접속되고 list.ejs에서 데이터베이스에 있는 데이터도 잘 가져오는데 ajax로 데이터 삭제하기만 안되는것같습니다.
버전은 이러합니다 list 주소로 들어가면 서버콘솔창에
데이터베이스 정보들은 잘가져오는데 강의에서 삭제관련해서는 전부 작동이 안되는것같습니다. 강의 정말도움많이 되고있습니다. 감사합니다.
-
글쓴이글
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
- 답변은 로그인 후 가능합니다.