Передать Javascript-переменные tp PHP-контроллер в Code Igniter

Привет всем, у меня есть этот javascript, который должен передать некоторые переменные, включая массив. Моя проблема в том, что я не могу передать эти значения с помощью uRL, потому что я могу иметь дело со многими значениями. Я пытаюсь использовать ajax JSON, но я просто не могу получить значения: Вот мой javascript:

$(function(){ $('#preview').click(function(){ var thesum=0; var rowid=[]; var rowfields=[]; var supplier = document.getElementById("sid").value; //need to pass var terms=document.getElementById("terms").value; //need to pass 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 $tbldata=JSON.stringify(rowfields);//need to pass window.location = '<?php echo base_url();?>index.php/main/retrievepo';// this is where i should get the passeddata });//preview click close });//function close 

Вот моя функция, расположенная в контроллере PHP (я использую codeigniter)

 public function retrievepo() { // should recieve data here $this->load->view('PurchaseOrderPreview'); } 

Любая помощь, пожалуйста? Я так долго укладывался сюда …

Почему бы вам не попробовать:

 $(function(){ $('#preview').click(function(){ var thesum=0; var rowid=[]; var rowfields=[]; var supplier = document.getElementById("sid").value; //need to pass var terms=document.getElementById("terms").value; //need to pass 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 tbldata=JSON.stringify(rowfields);//need to pass $.post('/index.php/main/retrievepo',{"tbldata" : tbldata},function(response) { //Load the response here to any div after ajax call //Eg: $('#div_id').html(response); });//preview click close }); }); 

Контроллер PHP:

 <? public function retrievepo() { // should recieve data here $data= $this->input->post('tbldata'); //pass the received post variables to view and access them inside your view.php $this->load->view('PurchaseOrderPreview',$data); } ?>