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



    ?>
  • 相关阅读:
    Linux cat
    Linux touch
    Win10 UAP 绑定
    Win10 资源文件
    Win10 启动模拟器
    Win10 安装Vs2015 社区版和企业版各个问题汇总
    Win10 开发者模式开启
    android 入门-本地化语言
    android 入门-基础了解
    wp8 入门到精通 定时更新瓷贴
  • 原文地址:https://www.cnblogs.com/HighKK/p/13088210.html
Copyright © 2011-2022 走看看