lost_in_river 2021-11-03 09:42 采纳率: 66.7%
浏览 34
已结题

使用ajax实现一个简单的删除功能,但是php文件中接收不到id值

test.html:
function del(id) {

    if(confirm("确定删除?")){
        $.ajax({
            url:"/app/controller/Del.php/" +id,
            success:function () {
                alert("删除成功");
            },
            error:function () {
            }
            }

        );
    }

}

Del.php:
public function del(){
$id_arr = isset($_GET['id']);

    $result =  Db::table('user')->where('id',$id_arr)->delete();

    //print_r($id_arr);

    if($result){
        echo json_encode(array("code"=>200));
    }else{
        echo json_encode(array('code'=>400));
    }

}

这是目录结构

img

index.php:
public function test(){

    $All = Db::table('user')->select()->toArray();
    $id = array_column($All,'id');
    $name = array_column($All,'name');
    $pwd = array_column($All,'pwd');

    /*Db::table('user')->where('id',3)->delete();*/

   /* $id_arr = isset($_GET['id']) ;

    Db::table('user')->where('id',$id_arr)->delete();

    print_r($id_arr);*/

test.html:

<table class="layui-table" id="demo" lay-filter="demo">
    <colgroup>
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th id="id" width="100px">ID<i class="layui-icon layui-icon-cols" style="font-size: 30px; color: #1E9FFF;"></i></th>
        <th width="400px">姓名<i class="layui-icon layui-icon-username" style="font-size: 30px; color: #1E9FFF;"></i> </th>
        <th width="400px">密码<i class="layui-icon layui-icon-password" style="font-size: 30px; color: #1E9FFF;"></i></th>
        <th width="400px">操作</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        {foreach $All as $key=>$nv}
    <tr>
        <th>
            {$nv.id}
        </th>
        <th>
            {$nv.name}
        </th>
        <th>
            {$nv.pwd}
        </th>
        <th>
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" data-type="getCheckData" onclick="show()" >查看</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="del()">删除</a>
            <!--<a href="{:url('index/test',['id'=>$nv.id])}">删除</a>-->
        </th>
    </tr>
    {/foreach}
    </tr>

    </tbody>






</table>
   View::assign('All',$All);
   View::assign('arrayid',$id);
   View::assign('arrayname',$name);
   View::assign('arraypwd',$pwd);

    return View::fetch();
}
  • 写回答

3条回答 默认 最新

  • 还是个小家伙 2021-11-03 15:18
    关注

    url:"/app/controller/Del.php?id=" +id,

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

报告相同问题?

问题事件

  • 系统已结题 12月9日
  • 已采纳回答 12月1日
  • 创建了问题 11月3日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度