duai0935 2013-04-03 07:01
浏览 35

使用codeigniter从javascript上调用控制器

hey guys i am facing trouble in calling controller method from javascript pls help . .

my view is

<script type="text/javascript">
    function kccbranchselect()
    {
        $.ajax({
        type : 'POST',
        data : 'addreceiptkccbranchid='+ $('#addreceiptkccbranch').val(),
        url : '<?php echo base_url();?>index.php/ctl_dbcont/getmembersbybranch',
        success :   function(data){
                        $('#addreceiptddsmember').val(data);
                    }
        });
    }
</script>
<select id="addreceiptkccbranch" name="addreceiptkccbranch" onChange="kccbranchselect();" tabindex="1" >
    <option value="">--SELECT--</option>
    <?php foreach($branchlist as $value):?>
        <option value="<?=$value['branch_id']?>"><?=$value['branch_name']?></option>
    <?php endforeach; ?>
</select>
<select id="addreceiptddsmember" name="addreceiptddsmember" tabindex="1">
    <?php foreach($member_by_branch as $row) { ?>
        <option value = ""></option>
    <?php } ?>
</select>

my controller is

function getmembersbybranch()
{
    $this->load->model('mod_user');
    $addreceiptkccbranchid      =   $_POST['addreceiptkccbranchid'];
    $data['member_by_branch']   =   $this->mod_user->member_receipt_dds($addreceiptkccbranchid);
    redirect('view_addreceipts');
}

i am generating a dropdown by selecting another dropdown option . . i cant access the controller method by putting url : '<?php echo base_url();?>index.php/ctl_dbcont/getmembersbybranch', in ajax ,why ??

  • 写回答

3条回答 默认 最新

  • douza1373 2013-04-03 07:10
    关注

    The redirect statement here is invalid, as it is an AJAX request. You have to send html or json response from server, which you can process at client side. e.g.

    $data['member_by_branch']=$this->mod_user->member_receipt_dds($addreceiptkccbranchid);
    echo $data['member_by_branch']; //assuming its html
    

    so on client side, you just have to use this statment in you callback method.

    $('#addreceiptddsmember').html(data);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题