duanfu3634 2014-10-13 08:10
浏览 54
已采纳

删除按钮在CodeIgniter中不起作用

Here's my Delete button:

<td>
    <a href="javascript:void(0);" onclick="delete(<?php echo $data->emp_id;?>);">
        <button id="button_delete">Delete</button>
    </a>
</td>

Here's my Javascript code:

<script type="text/javascript">
    var url="<?php echo base_url();?>";
    function delete(id)
    {
        var r=confirm("Do you want to delete this employee?");
        if (r==true)
        {
            window.location = url+"index.php/admin_logins/employee4/"+id;
        }
        else
        {
            return false;
        }
    }
</script>

Here's my controller (admin_logins.php) method -

function employee4($emp_id)
{
    $this->employee_model->delete_employee($emp_id);
    $this->index();
}

And here's my model(employee_model.php) method -

public function delete_employee($emp_id)
{
    $this->db->where('employee.emp_id',$emp_id);
    return $this->db->delete('employee');
}

My table name is employee and my database is MySQL.

Column Name         Datatype
   id                 int
  emp_id             varchar(15)
  emp_name           varchar(50)
  emp_mobile_no      varchar(15)

Whenever I click the Delete button, nothing happens. What am I doing wrong?

  • 写回答

4条回答 默认 最新

  • dtnpzghys01643322 2014-10-13 08:21
    关注

    It's the function name delete I tested it and gave me this error:

    Uncaught SyntaxError: Unexpected token delete

    So try to name it with another name, ex: deleteEntry or deleteEmployee

    delete is the javascript command so it's reserved word, and please always avoid to name functions or variables with reserved words

    Alternatively I suggest to use the solution:

    <td>
        <a href="index.php/admin_logins/employee4/<?php echo $data->emp_id;?>" 
           onclick="return confirm('Do you want to delete this employee?');">
            <button id="button_delete">Delete</button>
        </a>
    </td>
    

    Give a tags href, and onclick just return confirmation message

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题