2017-03-28 3 views
0

jqueryを使用してテーブルからデータを送信しようとしていますが、テーブルの値を取得するのにノードjsのPOSTメソッドでデータを送信しないようにしようとしています。 app.post( '/ send_data');htmlテーブルからnodejsにデータを送信するには?

$("#btnEnviarDatos").click(function() { 
$("#datatable-responsive tbody tr").each(function (index) { 
    var campo1, campo2, campo3, campo4, campo5, campo6, campo7, campo8, campo9; 
    $(this).children("td").each(function (index2) { 
     switch (index2) { 
      case 1: 
      campo1 = $(this).text(); 
      break; 
      case 2: 
      campo2 = $(this).text(); 
      break; 
      case 3: 
      campo3 = $(this).text(); 
      break; 
      case 4: 
      campo4 = $(this).text(); 
      break; 
      case 5: 
      campo5 = $(this).text(); 
      break; 
      case 6: 
      campo6 = $(this).text(); 
      break; 
      case 7: 
      campo7 = $(this).text(); 
      break; 
      case 8: 
      campo8 = $(this).text(); 
      break; 
      case 9: 
      campo9 = $(this).text(); 
      break; 
     } 
    }); 
    if(campo1!=undefined && campo2!=undefined && campo3!=undefined && campo4!=undefined && campo5!=undefined && campo6!=undefined && campo7!=undefined && campo8!=undefined && campo9!=undefined){ 
     alert(''+campo1 + ' - ' + campo2 + ' - ' + campo3+ ' - ' + campo4+ ' - ' + campo5+ ' - ' + campo6+ ' - ' + campo7+ ' - ' + campo8 + ' - ' + campo9); 
    }   
}); 

});

答えて

0

あなたはJSON.stringify ことを試してみて使いたい:

$('#btnEnviarDatos').click(function() { 
    var data = { trs: [] }; 
    $('#datatable-responsive tbody tr').each(function (index) { 
    var tr = {}; 
    $(this).children('td').each(function (index2) { 
     tr['campo'+index2] = $(this).text(); 
    }); 
    data.trs.push(tr); 
    }); 
    alert(JSON.stringify(data));  
}); 
関連する問題