Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要在CodeIgniter中将数组值从javascript传递到php控制器_Php_Javascript_Codeigniter_Jquery - Fatal编程技术网

需要在CodeIgniter中将数组值从javascript传递到php控制器

需要在CodeIgniter中将数组值从javascript传递到php控制器,php,javascript,codeigniter,jquery,Php,Javascript,Codeigniter,Jquery,我有一个javascript,它将可编辑的值存储在一个数组中: <script> $(function(){ $('#preview').click(function(){ var thesum=0; var rowid=[]; var rowfields=[]; var supplier = document.getElementById("sid").value; var terms=document.getElementById(

我有一个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>

$(函数(){
$(“#预览”)。单击(函数(){
var thesum=0;
var rowid=[];
var rowfields=[];
var供应商=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=($('#产品列表tr').length);
//循环启动
var i=0;
grid=$('#产品列表输入[type=“checkbox”]:选中”)。每个(函数(){
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(),单价:$row.find('td:eq(3)')).text(),数量:$row.find('td:eq(5)input').val(),金额:$row.find('td:eq(6)input').val());
i++;
});//每关一次
var dataString=JSON.stringify(行字段);
});//预览单击“关闭”
});//功能关闭
我需要将rowfields数组传递给我的控制器,以便开始操作其他函数上的数据。你能帮我做这个吗

jqueryajax

$(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
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

使用AJAX POST将数据发送到ControlOri实际不知道如何发送:(使用AJAX POST将数据发送到ControlOri实际不知道如何发送:(如果无法将输入值获取到$this->input->POST()中,请尝试使用此文件获取内容('php://input')这是我的控制器函数…如何检查数据是否已传递?公共函数retrievepoform(){$myPostData=$this->input->post();echo json_encode($myPostData);$this->load->view('PurchaseOrderPreview');}在服务器端,您需要使用json_decode()将字符串转换回JS函数,如果您想将其用作数组。如果您只需要存储在数据库中,最好将数据作为文本存储在一列中。获取如下值$data=json\u decode(file\u get\u contents('php://input);并像下面的打印($data)那样回显;我还是做不到:(除了ajax,我还想到了其他可能的方法……有什么建议吗?如果您无法将输入值输入到$this->input->post()中,请尝试使用此文件获取内容('php://input“)这是我的控制器函数…如何检查数据是否已传递?公共函数retrievepoform(){$myPostData=$this->input->post();echo json_encode($myPostData);$this->load->view('PurchaseOrderPreview');}在服务器端,如果要将字符串用作数组,则需要使用json_decode()函数将其转换回JS。如果只需要将数据存储在数据库中,则最好将数据作为文本存储在一列中。获取如下值$data=json_decode(file_get_contents('php://input’);并且像下面的print_r($data)那样回音;我仍然做不到:(除了ajax之外,我正在考虑其他可能的方法……有什么建议吗?