我正在尝试将数据从服务器端发送到我的ajax调用,但是它说net :: ERR_CONNECTION_REFUSED
我的客户端代码是
$.ajax({
url:'http://localhost:3000/calculateCost',
type: 'POST',
cache: false,
dataType: "json",
data: {FurnitureID: fID, FurnitureQty: fQty},
success: function(data){
console.log("success");
},
error: function(jqXHR, textStatus, err){
console.log("error");
}
})
服务器端代码
app.post('/calculateCost', urlEncodedParser, function(req, response){
var body = req.body;
var qstr = "SELECT Price FROM `Furniture` WHERE 1"//FurnitureID = '"+ body.FurnitureID+"'";
con.query(qstr, function(res,err,fields){
if(err){
throw err;
}
res.send({LOLOL:"lol"});
console.log("sent");
});
我使用的jquery是
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>