我无法将Codeigniter视图中的变量传递给控制器,然后使用模型来拍摄从数据库中获取数据所需的查询。将变量传递给javascript,codeigniter
这里是我的控制器(片段):
public function read() {
echo json_encode($this->random_model->getAll());
}
型号:
public function getAll() {
$id = $this->input->post('id');
$id = intval($id);
// print_r($sg_id);
// var_dump($sg_id);
$query = $this->db->where('id',$id)->limit(100)->get('table_name');
if($query->num_rows() > 0) {
return $query->result();
} else {
return array();
}
}
我从另一个函数发送 “$标识”:
function test1()
{
$blaa['id'] = $this->input->post('id');
if ($query = $this->model_name->getAll($blaa))
{
$blaa['records'] = $query;
}
//$this->model_name->getAll($blaa);
$this->load->view('view_name', $blaa);
}
这是test1 view:
<?php $attributes = array("class" => "", "id" => "", "name" => "");
echo form_open("test/test1/", $attributes);?>
<input type="text" id="id" name="id" >
<?php echo form_submit('submit', 'Submit')?>
<?php echo form_close(); ?>
这是显示所有数据VIEW_NAME,我使用的数据表:
All.js是在VIEW_NAME呈现(读取数据片段):
var readUrl = 'index.php/controller_name/read'
function readUsers() {
//display ajax loader animation
$('#ajaxLoadAni').fadeIn('slow');
$.ajax({
url: readUrl,
dataType: 'json',
success: function(response) {
for(var i in response) {
response[ i ].updateLink = updateUrl + '/' + response[ i ].id;
response[ i ].deleteLink = delUrl + '/' + response[ i ].id;
}
//clear old rows
$('#records > tbody').html('');
//append new rows
$('#readTemplate').render(response).appendTo("#records > tbody");
//apply dataTable to #records table and save its object in dataTable variable
if(typeof dataTable == 'undefined')
dataTable = $('#records').dataTable({"bJQueryUI": true});
//hide ajax loader animation here...
$('#ajaxLoadAni').fadeOut('slow');
}
});
的结果表明,我得到的仅仅是ID为“0”的数据,无论我通过测试控制器发送了哪个值。
在阿贾克斯你没有通过价值.. –