通过JavaScript变量TP PHP控制器在code点火器 [英] Pass Javascript Variables tp PHP Controller in Code Igniter
本文介绍了通过JavaScript变量TP PHP控制器在code点火器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我有这样的JavaScript,有传递一些变量,包括数组。我的问题是,我不能使用URL通过这些价值观,因为我可以处理许多值。我试图使用AJAX JSON,但我只是不能检索值:这里是我的javascript:
Hi everyone I have this javascript that has to pass some variables including an array. My problem is that I cannot pass these values using the uRL because i might deal with many values. I am trying to use ajax JSON but i just cannot retrieve the values: Here is my 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)
Here is my function, located in a PHP Controller (i am using codeigniter)
public function retrievepo()
{
// should recieve data here
$this->load->view('PurchaseOrderPreview');
}
任何帮助吗?我一直堆放在这里这么久了......
Any help please? I've been stacked from here for so long...
推荐答案
你为什么不尝试这样的:
Why dont you try like this:
$(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控制器:
PHP Controller:
<?
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);
}
?>
这篇关于通过JavaScript变量TP PHP控制器在code点火器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文