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



    ?>
  • 相关阅读:
    属性包装
    生成器
    迭代器
    深拷贝-浅拷贝
    装饰器-wrapper
    类别不均衡
    参数优化-学习曲线
    参数优化-验证曲线
    参数优化-API
    D. Number Of Permutations 符合条件的排列种类
  • 原文地址:https://www.cnblogs.com/HighKK/p/13088210.html
Copyright © 2011-2022 走看看