我有下面的代码:
<?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/