如何通过javascript函数调用codeigniter函数

时间:2013-08-28 04:59:52

标签: php javascript codeigniter

这在我的codeigniter函数中不起作用我有id并且无法获得该id.Please帮助我。这是我的观点,我试图通过函数发送我的id。

<script type="text/javascript">
    function makeajaxcall(id) {
        //alert(id);
        var r = confirm("Do you want to Delete");
        if (r == true) {
            window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user?id='.id);?>";
        } else {
            x = "You pressed Cancel!";
            alert(x);
        }

    }
</script>

3 个答案:

答案 0 :(得分:7)

更改此行:

window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user?id='.id);?>";

要:

window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user');?>?id="+id;

答案 1 :(得分:0)

尝试使用此

window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user/'.id);?>";

假设您的控制器中有这种方法

function admin_link_delete_user($id){
     echo $id;// u'll get the id which you are passing through javascript    
}

答案 2 :(得分:0)

<script type="text/javascript">
function makeajaxcall(id)
{
      //alert(id);
      var r=confirm("Do you want to Delete");
      if (r==true)
      {
           $.post("<?php echo site_url('controller_d/login/admin_link_delete_user/');?>", {id:id},
           function(data) {
                alert(data+"a");
           }, 'json');
      }
      else
      {
           x="You pressed Cancel!";
           alert(x);
      }

}
</script>  
控制器中的

function admin_link_delete_user(){
   echo $this->input->post('id');
   //perform your code
}