亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法 POST / Nodejs

無法 POST / Nodejs

楊__羊羊 2023-09-14 20:45:24
請幫助我解決這個錯誤,我長期以來一直在努力解決它。因此,我也無法將數據添加到我的數據庫中。任何幫助將不勝感激。這是我的index.js代碼這是我的routes.js代碼const {   con,   sessionStore } = require('./config/db');exports.new = function(req, res){    message = '';   if(req.method == "POST"){      const post  = req.body;      const username= post.username;      const title= post.title;      const state= post.state;      const category= post.category;      const description= post.description;       if (!req.files)                return res.status(400).send('No files were uploaded.');         const file = req.files.uploads;        const img_name=file.name;          if(file.mimetype == "images/jpeg" ||file.mimetype == "images/png"||file.mimetype == "images/gif" ){                                               file.mv('public/imgs/uploads/'+file.name, function(err) {                                               if (err)                     return res.status(500).send(err);                        const sql = "INSERT INTO `nt_data`(`username`,`title`,`state`,`category`, `images` ,`description`) VALUES ('" + username + "','" + title + "','" + state + "','" + category + "','" + img_name + "','" + description + "')";                             const query = con.query(sql, function(err, result) {                                 res.redirect('show/'+result.insertUsername);                            });                       });          } else {            message = "This format is not allowed , please upload file with '.png','.gif','.jpg'";            res.render('new.ejs',{message: message});          }   } else {      res.render('new');   } };exports.show = function(req, res){    let message = '';    const username = req.params.username;    const sql="SELECT * FROM `nt_data` WHERE `username`='"+username+"'";     con.query(sql, function(err, result){      if(result.length <= 0)      message = "show not found!";            res.render('show.ejs',{data:result, message: message});   });};請幫我解決這個錯誤,這非常重要。謝謝
查看完整描述

1 回答

?
蝴蝶刀刀

TA貢獻1801條經驗 獲得超8個贊

您的index.js 文件不包含路由的 POST 方法"/"。您可以使用以下示例添加一個:

app.post('/',function(req,res){
  //Your function code
  });


查看完整回答
反對 回復 2023-09-14
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號