Javascript从数组中提取数据并发送到数据库
我有一个获取表信息的数组,我需要将该数据发送到数据库。我不擅长js,所以请容忍我。数组是Javascript从数组中提取数据并发送到数据库,javascript,jquery,Javascript,Jquery,我有一个获取表信息的数组,我需要将该数据发送到数据库。我不擅长js,所以请容忍我。数组是 document.getElementById('sroute').onclick=( function(){ var arrayOfInvoices = $('#rtbl tr:not(:eq(0))').map( function(i,el) { return ({ invoice: el.id, stopnum: i+1 }) } ).get(); alert(
document.getElementById('sroute').onclick=( function(){
var arrayOfInvoices = $('#rtbl tr:not(:eq(0))').map( function(i,el) { return ({ invoice: el.id, stopnum: i+1 }) } ).get();
alert(JSON.stringify(arrayOfInvoices));
arrayOfInvoices.forEach(saveStop);
function saveStop() {
alert(arrayOfInvoices[0][0]);
/*$.post("rec_maint.php",{
maint: 'invoices',
rec: "stopnum",
invoice: saveStop[0][0];
rstop: saveStop[0][1]});*/
}
});
第一个警报是
[{"invoice":"148546","stopnum":1},{"invoice":"148541","stopnum":2},{"invoice":"148542","stopnum":3},{"invoice":"148543","stopnum":4},{"invoice":"148558","stopnum":5}]
第二个警报是“未定义”。请提供帮助。
ArrayFinVoices[0]。发票是一个对象,您需要使用键获取更多数据->ArrayFinVoices[0][“发票”]
,等等。您有后端吗?我知道了。在函数I之前添加了var cnt=0;并在函数中增加该值。函数中的警报现在为…警报(ArrayFinVoices[cnt][“invoice”]+“”+ArrayFinVoices[cnt][“stopnum]”);这就成功了!我将使用jquery中的数据发送到数据库。非常感谢。结果还是有问题。虽然代码在我只将数据发送到警报时起作用。问题是当我尝试在页面加载时使用“$.post…”时,post函数抛出“uncaughtsyntaxerror:Unexpected token;”错误。注释掉发票并将其扔到stopnum上。ArrayFinVoices[0]。发票是一个对象,您需要使用键获取更多数据->ArrayFinVoices[0][“发票”]
,等等。您有后端吗?我知道了。在函数I之前添加了var cnt=0;并在函数中增加该值。函数中的警报现在为…警报(ArrayFinVoices[cnt][“invoice”]+“”+ArrayFinVoices[cnt][“stopnum]”);这就成功了!我将使用jquery中的数据发送到数据库。非常感谢。结果还是有问题。虽然代码在我只将数据发送到警报时起作用。问题是当我尝试在页面加载时使用“$.post…”时,post函数抛出“uncaughtsyntaxerror:Unexpected token;”错误。注释掉发票并将其抛出stopnum。