【问题标题】:Error on update table by ajax , jquery and phpajax、jquery 和 php 更新表时出错
【发布时间】:2022-07-03 23:33:19
【问题描述】:

我有一段代码用于更新表格,但它不起作用。当我点击发送按钮时,页面将刷新,但不受影响在表格记录上并且不重定向。 为了调试,我在代码中添加了警报,但在浏览器的 Inspect 视图中我找不到 data.operation 值!

 $(document).on('click', '#send', function() {            
        data._id = $(this).attr("id");
        data.operation = "send";            
        alert('hello');
        $.ajax({
            url: "updatedetail.php",
            type: "POST",
            data: data,
            success: function(data) {
                $.redirect('order3.html', {
                    'orderid': _id
                });
            }
        });
    });

//updatedetail.php

if ($_POST['operation'] == 'send') {
    $query = "UPDATE orders SET status=:sid WHERE id=:id";
    $statement = $conn->prepare($query);
    $statement->bindParam(':sid', 2);
    $statement->bindParam(':id', $_POST['_id']);
    $result = $statement->execute();


    if (!empty($result)) {
        echo "data updated";
    }
}

有什么想法吗?

【问题讨论】:

    标签: php jquery ajax


    【解决方案1】:

    尝试在 ajax 中使用此错误日志记录

    error: function (request, status, error) {
       console.log(request.responseText);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 2017-02-25
      相关资源
      最近更新 更多