1

可能な値を配列に格納するこのJavaScriptがあります:

<script>
$(function(){
    $('#preview').click(function(){
    var thesum=0;
    var rowid=[];
    var rowfields=[];
    var supplier = document.getElementById("sid").value;
    var terms=document.getElementById("terms").value;
    var podate=document.getElementById("date1").value;
    var reqdate=document.getElementById("date2").value;
    var contp=document.getElementById("contactp").value;
    var count = ($('#listOfProducts tr').length);
    //loop start
    var i=0;
    grid=$('#listOfProducts input[type="checkbox"]:checked').each(function(){
    var $row = $(this).parents('tr'); 
    var $trid =$(this).closest('tr').attr('id');
    rowid[i]=$trid; 
    rowfields.push({itemname: $row.find('td:eq(0)').text(),       productname:$row.find('td:eq(1)').text(), productdesc: $row.find('td:eq(2)').text(), unitprice:$row.find('td:eq(3)').text(), quantity:$row.find('td:eq(5) input').val(), amount:$row.find('td:eq(6) input').val()});
    i++;
    });//each close 

var dataString = JSON.stringify(rowfields); 
   });//preview click close
 });//function close
 </script>

他の関数でデータの操作を開始できるように、rowfields 配列をコントローラーに渡す必要があります。これで私を助けてもらえますか?

4

1 に答える 1

1

Jquery ajax

$(document).ready(function(){

    $('#preview').click(function(){
    var thesum=0;
    var rowid=[];
    var rowfields=[];
    var supplier = document.getElementById("sid").value;
    var terms=document.getElementById("terms").value;
    var podate=document.getElementById("date1").value;
    var reqdate=document.getElementById("date2").value;
    var contp=document.getElementById("contactp").value;
    var count = ($('#listOfProducts tr').length);
    //loop start
    var i=0;
    grid=$('#listOfProducts input[type="checkbox"]:checked').each(function(){
    var $row = $(this).parents('tr'); 
    var $trid =$(this).closest('tr').attr('id');
    rowid[i]=$trid; 
    rowfields.push({itemname: $row.find('td:eq(0)').text(),       productname:$row.find('td:eq(1)').text(), productdesc: $row.find('td:eq(2)').text(), unitprice:$row.find('td:eq(3)').text(), quantity:$row.find('td:eq(5) input').val(), amount:$row.find('td:eq(6) input').val()});
    i++;
    });//each close 

    var dataString = JSON.stringify(rowfields);

    //ajax function 
    //http://api.jquery.com/jQuery.ajax/
      $.ajax({  
          //controller path
          url: "/path/to/url",  
          type: "POST",  
          dataType: "json",  
          contentType: "json",  
          data: dataString
          success: function(response){              
           console.log(response);
          },  
          error: function(response){  

              console.log(response);
          }  
        }); //ajax close



   });//preview click close
 });//function close
于 2013-08-05T04:20:33.410 に答える