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();
    }



    ?>
  • 相关阅读:
    强化学习
    nginx环境准备
    全面解读PHP-数据结构
    全面解读PHP-数据库缓存
    跨域问题的解决方法
    使用 apt-get 清理
    怎样用 Bash 编程:逻辑操作符和 shell 扩展
    怎样用 Bash 编程:语法和工具
    使用 split 命令分割 Linux 文件,使用 cat 合并文件
    通过tar包解压安装docker
  • 原文地址:https://www.cnblogs.com/HighKK/p/13088210.html
Copyright © 2011-2022 走看看