ajax 传递数组 nodejs,javascript - push data in Array AJAX/NodeJS - Stack Overflow

When I selected a service from select input, I got a div created by JS as below:

// SOME CODE IN HERE.................................

Service 1

1 x 500

500

Service 2

1 x 1500

1500

SUBMIT

I create Ajax variable for using in Nodejs:

$("button[type='submit']").click(function (){

var length = $('.service__title').length;

var data = [];

alert($('.service__title:eq(0)').text());

alert(parseInt($('.display__number:eq(0)').text()));

for(let i = 0; i < length; i++){

data.push({

title: $('.service__title:eq(i)').text(),

quantity: parseInt($('.display__number:eq(i)').text()),

subtotal: parseInt($('.display__total:eq(i)').text())

})

}

$.ajax({

async:false,

url: "../booking/success",

type: "POST",

dataType: "html",

data: {data:data},

contentType: "application/x-www-form-urlencoded",

})

});

and console log:

app.post('/booking/success', async (req,res)=> {

console.log(req.body);

console.log(req.body.data);

res.render("success");

})

When I clicked Submit, my array "data" is undefined.

{ data:

[ { title: ' ', quantity: 'NaN', subtotal: 'NaN' } ]

[ { title: ' ', quantity: 'NaN', subtotal: 'NaN' } ]

Please help me!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值