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

问题描述 投票:0回答:1

[当我想保存到提交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');
            }

          });
        });

    };
node.js node-mssql
1个回答
0
投票

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

        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');
          });
        });
© www.soinside.com 2019 - 2024. All rights reserved.