保存到数据库后永远等待本地主机

当我要保存到提交chrom上的数据库时,给我按摩等待localhost,这是永远的。我该如何解决这个问题。数据已保存,一切正常,哪里有问题...请帮助... enter code here

 const bodyParser = require('body-parser');
        const mysql = require('mysql');
        var urlencodedParser = bodyParser.urlencoded({extended: false});


        var connection = mysql.createConnection({
            host:'127.0.0.1',user:'root',password: '',database: 'sm_db'

        });
        connection.connect(function(err){
            if(!err){
                console.log('CONNECTED');
            } else{
                console.log('ERROR');
            }
        });

        app.post('/',urlencodedParser,function(req,res){
            const germant = req.body.germant;
            const germantMsqlData = {germant};
        connection.query('INSERT INTO summersidedatatable SET ?',germantMsqlData,function (error,results,fields) {
            if (error) {
            res.send('SEND GERMANT DATA ERROR');
            }

          });
        });

    };
tmroybq 回答:保存到数据库后永远等待本地主机

您的错误是,如果没有错误,您不会发送响应:

        app.post('/',urlencodedParser,function(req,res){
            const germant = req.body.germant;
            const germantMsqlData = {germant};
        connection.query('INSERT INTO summersidedatatable SET ?',germantMsqlData,function (error,results,fields) {
            if (error) {
            res.send('SEND GERMANT DATA ERROR');
            }
             //here you are missing something
             res.send('Done with query');
          });
        });
,

替换

 const germantMsqlData = {germant};

 用下面的代码。请提供您的数据库字段名称

  const germantMsqlData={
      "data_base_field_name":germant
         }

在这里您已经提到了错误部分成功部分,而您没有提到。  res.send();

尝试输入我的代码

app.post('/',res){
            const germant = req.body.germant;
            const germantMsqlData={
          "data_base_field_name":germant
            }
        connection.query('INSERT INTO summersidedatatable SET ?',fields) {
            if (error) {
            res.send('SEND GERMANT DATA ERROR');
            }

             res.send('Redirect');
          });
        });

将data_base_field_name替换为您的字段名称

,

您错过了完成请求的时间,那么您的浏览器将永远等待

        app.post('/',fields) {
            if (error) {
                return res.send('SEND GERMANT DATA ERROR'); // finish the request in error case 
            }
            res.end(); // finish the request in success case,just end the request,does not send any data back to client.

          });
        });
本文链接:https://www.f2er.com/2928430.html

大家都在问