zoukankan      html  css  js  c++  java
  • 6.10ajax举例

    $('.del').click(function(){
            var id = $(this).data('id');
            var that = $(this);
            layer.confirm('确定删除'+id+'吗?',{icon: 3,title: '提示'},
            function(index){
              $.ajax({
                //ajax用法
                url:'/ajax.php',
                //与哪个文件进行传递
                type:'post',
                //传递方式
                data:{id:id},
                dataType:'json',
                //返回类型
                success:function(res){
                  //执行函数
                  console.log(res);
                  layer.close(index);
                  if (res.code==1){
                    location.reload();
                  }else{
                    layer.msg('删除失败!');
                  }
                }

              });
            });
    在HTML文件适当位置用class为del的标签即可应用
    ajax.php
    <?php
    if ($_POST){
        $ids = $_POST['id']; 
        $conn = new mysqli('localhost','root','root','ceshi');
        $sql = "select * from product where id = $ids";
        $res = $conn->query($sql);
        //连接数据库老一套
        $arr = [];
        if ($res){
            $arr['code'] = 1;
            //删除成功输出1
        }else{
            $arr['code'] = 2;
            //删除失败输出2
        }
        echo json_encode($arr);
        $conn->close();
    }



    ?>
  • 相关阅读:
    NOJ 1116 哈罗哈的大披萨 【淡蓝】 状态压缩DP
    优先队列原理与实现【转】
    testC-I
    济南NOIP冬令营 选拔(select)
    P4747 D’s problem(d)
    P4746 C’s problem(c)
    P4745 B’s problem(b)
    P4744 A’s problem(a)
    [bzoj] 1004: [HNOI2008]Cards
    NOIP2013 表达式求值
  • 原文地址:https://www.cnblogs.com/HighKK/p/13088210.html
Copyright © 2011-2022 走看看