execute(array(':field' =-6ren">
gpt4 book ai didi

javascript - 更新textarea上的mysql数据点击关闭

转载 作者:行者123 更新时间:2023-11-30 00:50:47 25 4
gpt4 key购买 nike

我有下面的代码:

<?php
$stmt = $pdo_conn->prepare("SELECT * from controldata where field = :field ");
$stmt->execute(array(':field' => 'notice_board'));
$result = $stmt->fetch();
?>
<textarea id="notice_board_textarea" data-id="notice_board" rows="8"><?php echo stripslashes(strip_tags($result["value"])); ?></textarea>
<script type="text/javascript">
$('#notice_board_textarea').on('blur', function () { // don't forget # to select by id
var id = $(this).data('id'); // Get the id-data-attribute
var val = $(this).val();
$.ajax({
type: "POST",
url: "dashboard.php?update_notice_board=yes",
data: {
notes: val, // value of the textarea we are hooking the blur-event to
itemId: id // Id of the item stored on the data-id
},
});
});
</script>

从 MySQL 数据库中选择数据并将其显示在文本区域中

然后 JS 代码通过将数据发布到另一个页面来更新它,但不刷新页面或单击保存/提交按钮

在dashboard.php上我有这个代码:

if($_GET["update_notice_board"] == 'yes')
{
$stmt = $pdo_conn->prepare("UPDATE controldata SET value = :value WHERE field = :field ");
$stmt->execute(array(':value' => $_POST["notes"], ':field' => 'notice_board'));
}

但它没有更新数据

我做错了什么吗?

最佳答案

错误:

if ($_POST["update_notice_board"] == 'yes') {

右:

if ($_GET['update_notice_board'] == 'yes') {

当您直接将某些内容附加到 URL 时,它总是 GET:

url: "dashboard.php?update_notice_board=yes",

关于javascript - 更新textarea上的mysql数据点击关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20998060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com