简体   繁体   English

需要将数组值从JavaScript传递到Code Igniter中的php控制器

[英]Needs to pass array values from javascript to php controller in Code Igniter

I have this javascript that stores able values in an array: 我有这个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>

i need to pass the rowfields array to my controller so i can start manipulating the data on other functions. 我需要将rowfields数组传递给控制器​​,以便可以开始处理其他函数上的数据。 Can you please help me with this? 你能帮我吗?

Jquery ajax 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在代码点火器中传递Javascript变量tp PHP控制器 - Pass Javascript Variables tp PHP Controller in Code Igniter 将多个文本框值传递给控制器​​代码点火器 - pass multiple textbox values to controller Code igniter 如何在代码点火器中将数组值从视图发送到控制器 - How to send array values from view to controller in code igniter 将数组值从 javascript 代码传递给 php - Pass the array values from javascript code to php 代码点火器-如何将索引数组从控制器传递到视图而不将索引数组更改为关联数组 - Code igniter-How to pass the indexed array from controller to view without making the indexed array to associative array 如何将多个复选框值从视图传递到控制器(使用代码点火器框架) - How to pass multiple checkbox values from view to controller (using code igniter frame work) 如何在代码点火器中将值从控制器传递到视图? - how to pass value from controller to view in code igniter? 如何在代码点火器中将变量从一个控制器传递到另一个控制器 - how to pass a variable from one controller to the other in Code igniter 会话值不在代码点火器中从一个控制器传递到另一个控制器 - session values not passing from one controller to another in code igniter 如何在控制器的代码点火器表中显示值? - How to display a values in code-igniter table from controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM