使用AJAX根据Codeigniter中的下拉值获取数据库值
16lz
2021-01-22
I want to retrieve value from database based on dropdown value using the ajax.
Here I'm attaching the screenshot thats what exactly I need. Once we change the year the result should be changed.
我想使用ajax根据下拉值从数据库中检索值。这里我附上截图,这正是我需要的。一旦我们改变了年份,结果就会改变。
So please help me to do this task. Thanks in Advance :)
所以请帮我完成这个任务。提前谢谢:)
3 个解决方案
#1
1
<script type="text/javascript">
jQuery(document).ready(function(){
$("#district").change(function() {
var vdcID = {"district_id" : $('#district').val()};
$.ajax({
type: "POST",
data: vdcID,
url: "<?php echo base_url(); ?>admin/ajax/showVdcById",
dataType: 'json',
success: function(data){
$('#vdc').html("<option>Please Select VDC</option> ");
$.each(data, function(i, data){
$('#vdc').append("<option value='"+i+"'>"+data+"</option>");
});
}
});
});
});
this code might help you. it takes value from from a dropdown and updates value on another dropdown based on the id it sends to database
这段代码可能会对您有所帮助。它从下拉菜单中获取值,并根据发送到数据库的id更新另一个下拉菜单的值