• Jquery ajax 完整实例子1


    $ajax请求---------------------------------

    var $personWifePs=$("#wife-money tbody tr");
    var $personWife=$("#wife-money").find("input.write");
    var $val=null;
    $.ajax({
    type: "POST",
    url: "data/hm_monery_serceh.php",
    success: function(dtmonery){
    var $list = JSON.parse(dtmonery);
    for(info in $list) {
    $personWifePs.append(`<td>
    <input id="d${n+=1}" value="${$list[info].monery}" class="write" type="text"/>
    </td>`)
    $personWife.val($list[info].monery);
    }
    }
    });

    $personWifePs.on("change",".write",function(){
    var $iput=$(this);
    $val=$(this).val();
    var $index=$personWifePs.children().find("input").index($(this)[0]);
    $.ajax({
    type: "POST",
    url: "data/hm_monery_update.php",
    data: "id="+($index+1)+"&monery="+$val,
    success: function(dtmonery){
    var $listone = JSON.parse(dtmonery);
    $iput.val($listone.monery);
    }
    });
    });

    PHP公共---------------------------------

    <?php
    //1:将连接数据库与设置编码程序保存
    // init.php中
    //2:哪个php需要数据库连接
    // require('init.php');
    //require加载-->init.php
    $conn = mysqli_connect('127.0.0.1','root','','home');
    $sql = "SET NAMES UTF8";
    mysqli_query($conn,$sql);
    ?>

    更新PHP-------------------

    <?php
    //1:修改响应数据类型
    header("Content-Type:text/plain;charset=utf-8");
    //2:获取所有参数
    @$n = $_REQUEST['id'] or die("-2");
    @$m = $_REQUEST['monery'] or die("-3");
    //3:连接数据库 设置编码
    require("init.php");
    //4:创建sql 发送sql
    $sql = "UPDATE hm_moneryone SET monery =$m WHERE id = $n ";
    $result = mysqli_query($conn,$sql);

    $sql = "SELECT * FROM hm_moneryone WHERE id=$n";
    $result = mysqli_query($conn,$sql);
    $back = mysqli_fetch_assoc($result);
    $json = json_encode($back);
    echo $json;
    ?>

    查询PHP--------------------

    <?php
    //0:修改响应头消息 text/html
    header("Content-Type:text/html;charset=utf-8");
    //2:连接数据库 设置编码
    require("init.php");
    //3:创建sql 发送sql
    $sql = "SELECT * FROM hm_moneryone";
    //4:抓取多行记录
    $result = mysqli_query($conn,$sql);
    $rows = mysqli_fetch_all($result,MYSQLI_ASSOC);
    $json = json_encode($rows);
    echo $json;
    ?>

  • 相关阅读:
    redhat 7.6 常用命令
    redhat 7.6 VI编辑操作
    redhat 7.6 网络配置
    华为学习配置笔记-01 配置con密码
    redhat 7.6 ssh 服务配置
    web前端面试第一次[addEventListenr();绑定事件]
    redis集群搭建
    linux服务器重启后redis数据丢失问题
    redis日志文件路径的设置
    linux下redis安装使用
  • 原文地址:https://www.cnblogs.com/dianzan/p/7461076.html
Copyright © 2020-2023  润新知