有2个下拉列表:
我的问题是:选择Project
后,Plot Details
获取正确填充,但当Dropdown Plot Details
被选中时,Chrome会挂断。< / p>
要继续,我必须刷新页面。我希望Plot Details
(下拉)值调用另一个ajax调用。
的javascript
$(document).ready(function() {
$('.get_member_name').live('change', function() {
alert('hello')
var project = $('#project').val();
var plot_details = $('#plot_details').val();
var base_url = $('#base_url').val();
if (project && plot_details) {
$.ajax({
type: "POST",
url: base_url + "admin/get_member_name",
data: {'category': category},
dataType: "html",
success: function(result) {
alert(result)
}
})
}
});
})
HTML
<div class="form-group">
<label class="col-md-3 control-label" for="inputSuccess">
Plot Details :
</label>
<div class="col-sm-9">
<select class="form-control get_member_name" name="plot_details" required="required" id="plot_details">
<option value="" id="opp12">Select Plot</option>
</select>
</div>
</div>
PHP
public function get_plot_details() {
if ($this->session->userdata('role_id') == 1) {
$data['record'] = $this->db->get_where('plot_details', array('project_id' => $this->input->post('project')))->result();
print_r($this->load->view('admin/ajax_data', $data, TRUE));
} else {
redirect('home/login');
}
}
查看页面
if (isset($record) && $record != NULL && $record != "") {
foreach ($record as $m) {
echo '<option value="' . $m->id . '"> ' . $m->plot_number . ' Area ' . $m->total_area . '</option>';
}
}
答案 0 :(得分:0)
我可以看到你使用了&#39; project&#39;在你的PHP中从DB获取记录。但是在你的ajax中,你传递的是请求数据&#39;类别&#39;。可能是这个导致问题。而不是
$.ajax({
type: "POST",
url: base_url + "admin/get_member_name",
data: {'category': category},
dataType: "html",
success: function(result) {
alert(result)
}
})
使用
$.ajax({
type: "POST",
url: base_url + "admin/get_member_name",
data: {'project': project},
dataType: "html",
success: function(result) {
alert(result)
}
})