我正在创建一个文本框,该文本在用户键入后无需提交便会自动更新为mysql,现在的问题是该文本框不会更新数据库 这是我参考以下所有观点进行编辑的结果,虽然仍然存在一些问题,但是总比没有显示好。
这是文本框输入:
echo "<td class=\"align-center\"><input type=\"text\" name=\"comment\" id=\"comment\" onKeyPress=\"getComment($id,this)\" /></td>";
我的JavaScript:
function getComment(id, txt_box)
{
var value = txt_box.value;
$.ajax({
'url': 'updatecomment.php',
'data': {"id": id, "comment": value},
'success': function (response) {
console.log(response);
//TODO: use server response
}
});
}
最后是updatecomment.php:
<?php require_once("../includes/connection.php") ?>
<?php require_once("../includes/functions.php") ?>
<?php
$id =$_GET['id'];
$comment = $_GET['comment'];
$query = "UPDATE tblinternapplication SET comment = '".mysql_real_escape_string($comment) ."' WHERE id = $id";
$result = mysql_query($query, $connection);
?>