我是 code igniter 的新手,我在 StackOverflow 线程数中搜索了以下问题,但似乎没有一个能解决我的问题。
我有以下 View 代码:
<select name="select1" id="select1">
<option value="0">None</option>
<option value="1">First</option>
</select>
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
// Ajax post
$(document).ready(function() {
$("#select1").change(function(event) {
event.preventDefault();
var id = $(this).val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/mycontroller/method",
dataType: 'json',
data: {id: id},
success: function(res) {
}
});
});
});
</script>
好的,当我更改下拉列表选择时没有任何反应,这实际上应该调用我的 Controller 方法。你能帮我解决这个问题吗?
谢谢
最佳答案
您正在使用 <select>
ID 为 category
但是在 jquery 中你调用了 $("#select1").change(function(event)
像这样。
你只需要改变$("#select1").change(function(event)
到
$("#category").change(function(event)
关于javascript - 下拉列表更改中的 JQuery 在 codeigniter 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38628274/