下拉列表更改中的JQuery在codeigniter中不起作用

siv*_*iva 3 javascript ajax model-view-controller jquery codeigniter

我是代码点火器的新手,我在StackOverflow线程的数量上搜索了以下问题,但它们似乎都没有解决我的问题.

我有以下视图代码:

<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>
Run Code Online (Sandbox Code Playgroud)

好的,当我更改下拉列表选择时,没有任何反应,实际上应该调用我的控制器方法.你能帮我解决这个问题吗?

谢谢

小智 5

你正在使用<select>id作为category

但是在jquery你这样称呼$("#select1").change(function(event).

你只需要换$("#select1").change(function(event)

$("#category").change(function(event)