【发布时间】:2021-01-08 04:21:17
【问题描述】:
我创建一个 AJAX 如下:
<script>
$("button[type='submit']").click(function (){
var length = $('.service__title').length;
var title = [];
var quantity = [];
var subtotal = [];
for(let i = 0; i < length; i++){
title.push($('.service__title').eq(i).text());
quantity.push(parseInt($('.display__number').eq(i).text()));
subtotal.push(parseInt($('.display__total').eq(i).text()));
}
$.ajax({
url: "../booking/success",
type: "POST",
data: {title:title, quantity:quantity, subtotal:subtotal}
// contentType: "application/x-www-form-urlencoded"
});
});
</script>
当我在终端控制台登录 req.body 时,我得到:
{
title: [
'1 x Private Self Makeup Class',
'Bridesmaid Look + Hair/Hijab do (no retouch)'
],
quantity: [ '6', '3' ],
subtotal: [ '4200000', '900000' ]
}
{
Dkhang: 'Viasss',
DPhone: '0943064201',
DEmail: 'q12@gmail.com',
DDate: '2020-09-16',
DTime: '00:00',
DAdress: 'Holo',
DTinh: '11',
DQuan: '11',
service: '32',
DComment: ''
}
请指导我如何在服务器的 index.js 中使用 Ajax。我不能跑
app.post("/", function(req,res){
let x = req.body.title.join(", ");
sql_text="SELECT * FROM Service WHERE Title IN ("+ x +")";
db.query(sql_text, (err, rows)=>{
if(err) res.send(err)
else{
res.render("services")
}
})
})
当我控制台记录 req.body.title 时,我得到 2 个对象:标题和未定义对象 请帮帮我!!!
【问题讨论】:
标签: html css node.js sql-server ajax