我在我的控制器中這樣的代碼,這段代碼我從示例代碼中獲得,但是當我嘗試使用我的表時,它不工作來填充另一個下拉列表。AJAX不與codeigniter
我的控制器
class Bkp extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('modelRegister');
}
function carselection() {
$arrCarbrand = $this->modelRegister->loadcarbrand();
foreach ($arrCarbrand as $carbrand) {
$arrcar[$carbrand->make] = $carbrand->make;
}
$data['make'] = $arrcar;
$this->load->view('car',$data);
}
function ajax_call() {
if (isset($_POST) && isset($_POST['make'])) {
$make = $_POST['make'];
$arrModels = $this->modelRegister->loadmodelfrombrand($make);
//print_r($arrModels);
foreach ($arrModels as $models) {
$arrmodels[$models->model] = $models->model;
}
print form_dropdown('model',$arrmodels);
} else {
redirect('site');
}
}
}
我查看
<?php
$this->load->helper('html');
?>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#makecombox select').change(function() {
var selMake = $(this).val();
console.log(selMake);
$.ajax({
url: "bkp/ajax_call",
async: false,
type: "POST",
data: "make="+selMake,
dataType: "html",
success: function(data) {
$('#model').html(data);
},
})
});
});
</script>
</head>
<body>
<div id="mydoubts">
<div id="makecombox"><?php echo form_dropdown('make',$make); ?></div>
<div id="model"></div>
</div>
</body>
</html>
當我嘗試使用它的工作示例代碼,但是當我試圖用我的表改變變量它不工作,請告訴我哪一行錯了?
試圖通過這樣的數據的數據:{「國家」:selCountry}, – JYoThI
,你也不必POST名稱,如$ _ POST [「讓」];這是在你的控制器中使用 – JYoThI
您好@jothi我的壞,我粘貼錯誤的觀點,請再次看到上面... –