module.exports.addPerson = function (req) {
return new Promise(function(resolve,reject){
var name = req.body.name
db.all('INSERT INTO person (name) VALUES ("'+name+")',function(err){
if(!err){
resolve("success")
}else{
reject(err)
}
})
})
}
Because the ajax code does not return the error:
var name= $('#name').val();
$.ajax({
url: 'http://localhost:3000/class/add',
data: {name:name},
type: 'POST',
success: function(data){
alert('success')
}, error: function(jqXHR, exception) {
alert('error')
}
})
In the event that the data is added correctly, a message will be displayed for that. In the case of a data conflict, no message will be displayed for that.