我有textarea并使用ajax将数据插入数据库但是我希望能够实时编辑文本区域,就像facebook在编辑注释时一样。到目前为止,我已将数据插入数据库,但我无法让textarea消失并显示插入的文本。有人可以给我提示吗?
HTML
<textarea row="5" col="20" id="md">
<button href="javascript:void(0);" onclick="mdmsg();">Save</button>
JS
function mdmsg() {
var md = $("#md").val();
if (md == "") {
$("#errormsg").fadeIn('slow').html('<div class="errorreg">enter some text.</div>');
} else {
var dataString = 'md=' + md;
$.ajax({
type: "POST",
url: "test?targ=mdmsg",
data: dataString,
success: function (response) {
$('#md').html(response);
}
});
}
}
PHP
if(isset($_GET["targ"]) == "mdmsg")
{
$cont = $_POST['md'];
$upd = $db->prepare("update users set bio = ? where user_name = ?");
echo $db->error;
$upd->bind_param('ss', $cont, $username->username);
$upd->execute();
echo "success";
$hg = $db->prepare("select `bio` from users where user_name = ?");
echo $db->error;
$hg->bind_param('s', $username->username);
$hg->execute();
$res = $hg->get_result();
while($row = $res->fetch_assoc())
{
echo "<div id='dvv'>".$row['bio']."</div>";//I want this row to show up on the textarea.
}
}