我使用quill来编写富文本并能够从div读取数据。但插入时没有DB或代码抛出的错误,但是数据没有进入DB。有人请帮助我解决问题。
function addComment() {
var quill = new Quill('#comment');
var cc = quill.getContents();
var reqBody = {
"comment": cc
};
$.ajax({
type: "post",
data: JSON.stringify(reqBody),
url: "addcomment",
dataType: 'json',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
success: function(data) {
console.log(data);
},
error: function(e) {
console.log("ERROR : ", e);
}
});
}
<div id="standalone-container">
<div id="toolbar-container">
<span class="ql-formats">
<select class="ql-font"></select>
<select class="ql-size"></select>
</span>
<span class="ql-formats">
<button class="ql-bold"></button>
<button class="ql-italic"></button>
<button class="ql-underline"></button>
<button class="ql-strike"></button>
</span>
<span class="ql-formats">
<select class="ql-color"></select>
<select class="ql-background"></select>
</span>
<span class="ql-formats">
<button class="ql-script" value="sub"></button>
<button class="ql-script" value="super"></button>
</span>
<span class="ql-formats">
<button class="ql-header" value="1"></button>
<button class="ql-header" value="2"></button>
<button class="ql-blockquote"></button>
<button class="ql-code-block"></button>
</span>
<span class="ql-formats">
<button class="ql-list" value="ordered"></button>
<button class="ql-list" value="bullet"></button>
<button class="ql-indent" value="-1"></button>
<button class="ql-indent" value="+1"></button>
</span>
<span class="ql-formats">
<button class="ql-direction" value="rtl"></button>
<select class="ql-align"></select>
</span>
<span class="ql-formats">
<button class="ql-link"></button>
<button class="ql-image"></button>
<button class="ql-video"></button>
<button class="ql-formula"></button>
</span>
<span class="ql-formats">
<button class="ql-clean"></button>
</span>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="min-height:50px;" name="comment" id="comment" placeholder="Comment"></div>
<div class="col-lg-2 pull-right" style="top:5px;">
<button type="button" class="btn btn-info" name="submit" onclick="addComment()">Add</button>
</div>
</div>
请查看上面的代码以便了解问题。当我调用此函数时,没有数据插入数据库。
答案 0 :(得分:1)
我可以使用以下代码在数据库中插入HTML:
var quill = new Quill('#comment'); var cc = quill.container.firstChild.innerHTML;
现在cc将保存可插入数据库的输入内容。