[当我想保存到提交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');
}
});
});
};
您的错误是,如果没有错误,您将不发送响应:
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');
});
});