只是为了确保我理解你,你正试图将一个变量从 javascript 传递给 CodeIgniter 的控制器函数,对吗?
如果这是您的情况(希望是),那么您可以使用 AJAX,或制作锚链接。
首先,您将使用URI 类,特别是segment()
函数。
假设这是您的控制器:
class MyController extends CI_Controller
{
function input(){
$parameter = $this->uri->segment(3);//assuming this function is accessable through MyController/input
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('mod_user');
$this->mod_user->insertdata();
}
}
现在使用 javascript,您可以制作锚标记或使用 AJAX:
方法1:通过制作锚标签:
<a href="" id="anchortag">Click me to send some data to MyController/input</a>
<script>
var $rowCount=0;
function invest() {
$rowCount=$('#ulinvestment').find('.rowInvestment').length;
}
$('#anchortag').prop('href', "localhost/index.php/MyController/input/"+$rowCount);
</script>
方法2:通过使用AJAX:
var $rowCount=0;
function invest() {
$rowCount=$('#ulinvestment').find('.rowInvestment').length;
}
//Send AJAX get request(you can send post requests too)
$.get('localhost/index.php/MyController/input/'+$rowCount);