【发布时间】:2015-08-03 17:31:23
【问题描述】:
我正在尝试使用 ajax/jquery 将 summernote 值存储到 database 但它只是将此值发送到数据库字段---- -> [object 对象].
HTML:
<div class="form-group">
<label for="description">Desciption</label>
<textarea name="description" id="description" class="summernote"></textarea>
</div>
<div class="text-right">
<a href="#" class="btn btn-primary" id="publish">Publier</a>
</div>
Js 文件:
$("#publish").on('click', function(e){
e.preventDefault();
var description = $('textarea[name="description"]').html($('.summernote').code());
$.ajax({
url : 'ajax/newpost.php',
data : 'description=' + description,
success : function(data){
alert(data);
location.reload();
}
});
});
newpost.php
require_once('../config/connect.php');
$description = $_GET['description'];
$stmt = $PDO->prepare("INSERT INTO `forum_posts` (`description`) VALUES(?)");
$stmt->execute(array($description));
if($stmt){
echo "done ......................";
}else{
echo "error ..................";
}
【问题讨论】:
-
console.log(description)在你的 JS 代码中,你可能会发现它是一个 jquery 对象。 -
顺便说一下,我认为 POST 请求更适合这个。
-
我尝试了 POST 请求,但它也不起作用。你能给我举个例子吗?也许你的方法会有所帮助
标签: php jquery summernote