我只想使用 ajax 将数据传递给控制器,这是通过视图中的下拉菜单选择的。这是我的尝试http://pastebin.com/KnLqW8Pc。
//// controller ///////
<?php
class Ilce extends CI_Controller{
public $ilceid;
public function __construct()
{
parent::__construct();
$this->load->model('ilce_model');
}
public function index()
{
$this->load->helper(array('form'));
$data['ilce'] = $this->ilce_model->ilce_getir();
$this->load->view('ilce', $data);
/*
hello, i want to print here to data which will select in view and passed by jsfunc file ( ajax ) to here again...
*/
}
}
/////////////////////////////////view/////////////////////////////////
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="style/reset.css"/>
<link rel="stylesheet" type="text/css" href="style/page.css"/>
<link rel="shortcut icon" href="img/3burcak.ico" />
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jfunc.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>3Burçak Ltd.Şti.</title>
</head>
<?php echo form_open('ilce/index')?>
<select id="ilce" name="ilce">
<option value="">Select Town</option>
<?php foreach ($ilce as $x):?>
<option value="<?php echo $x['id']?>"><?php echo $x['ad']?></option>
<?php endforeach?>
</select>
<select id="semt">
<option value="">Please select Town first.</option>
</select>
////////////////////////////////////////////////////////jsfunc
$(文档).ready(函数(){
/* il ilce arama*/
$("#ilce").change(
function(){
if($("#ilce").val()!="-1"){
var ilceid=$("#ilce").val();
$.post('ilce/index',{"ilceid":ilceid},function(output){
$('#semt').remove();
$('#semt').append(output);
});
}
});
/* il ilce arama bitti*/
});