think php jq ajax删除

表单展示页面
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>
<table class="table">
<tr>
    <td>商品名称</td>
    <td>商品图片</td>
    <td>商品分类</td>
    <td>状态</td>
    <td>商品库存</td>
    <td>本店售价</td>
    <td>操作</td>
</tr>

    {foreach $data as $k=>$v}
    <tr id="del">
        <td>{$v.name}</td>
        <td><img src="{$v.img}" alt=""></td>
        <td>{$v.cate}</td>
        <td>{$v.put}</td>
        <td>{$v.reserve}</td>
        <td>{$v.price}</td>
       <td>
           <a href="{:url(‘homework/homework/edit‘,[‘id‘=>$v.id])}">编辑</a>
           <a href="javascript:void(0)" onclick="del({$v.id})">删除</a>
       </td>
    </tr>
    {/foreach}
</table>
</body>
</html>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>

function del(id){
    $.ajax({
        url:/homework/homework/delete/id/+id,
        type:GET,
        dataType:json,
        success:function (res){
            if (res.code==200){
                alert(删除成功);
                $(#del).remove();

            }
        }

    })
}




</script>

控制器页面

 public function delete($id)
    {
        //调用删除的模型
        $res=HomeworkModel::del($id);
//返回json
        return json([code=>200,msg=>success,data=>$res]);


    }

//模型

    //删除
    public static function del($id)
    {
        return self::destroy($id);

    }

 

think php jq ajax删除

上一篇:centos7 安装phantomjs 记录


下一篇:手写CSS之实际开发中用到的几个典型实现