繁体   English   中英

AJAX 不更新 MySql 数据

[英]AJAX not updating MySql data

我创建了这个 PHP 脚本来更新用户的状态。 运行以下代码时遇到一些困难。 该页面的代码如下:-

    $query = "DELETE FROM users WHERE id='$id' ";
    $query_run = mysqli_query($conn, $query);

    if($query_run)
    {
        $_SESSION['status'] = "Successfully Deleted";
        header('Location: index.php');
    }
    else
    {
        $_SESSION['status'] = "Something Went Wrong.!";
        header('Location: index.php');
    }

此处的查询无法运行。 以下 ajax 代码使用 POST 请求将数据发送到此页面

$.ajax({
            type: "POST",
            url: "code.php",
            data: {
                    'checking_edit_btn': true,
                    'student_id': stud_id,
                      },
            success: function (response) {
            $.each(response, function (key, value) { 
            $('#edit_id').val(value['id']);
            });
            $('#editStudentModal').modal('show');
            };
            });

更新它现在正在工作,这是最终代码:

$.ajax({
        type: "POST",
        url: "code.php",
        data: {
               'delete_student': true,
                'student_id': stud_id,
                  },
        success: function (response) {
        $.each(response, function (key, value) { 
        $('#edit_id').val(value['id']);
        });
        $('#editStudentModal').modal('show');
        };
        });

你在哪里发送'update_student'/'delete_student'?

尝试添加到数据

update_student: true

要么

delete_student: true

取决于按钮

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM