我正在使用 tinymce 在 CodeIgniter 中发布数据,但是在某些情况下无法从 tinymce 编辑器获取数据。能够获取数据并将其存储在数据库中,但是大多数时候无法获取数据。正在提供我使用过的jquery代码和 ckeditor 脚本,请让我知道如何获取数据
$content = strip_tags(trim($this->db->escape_str($this->input->post('content'), " ")));
<script type="text/javascript">
$(document).ready(function () {
if($("#content").length > 0){
tinymce.init({
selector: "textarea#content",
theme: "modern",
height:300,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l ink image | print preview media fullpage | forecolor backcolor emoticons",
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
]
});
}
});
</script>
<script>
$(function() {
$('#edit_article').validate({
rules: {
"title": {
required: true
},
"content":{
required: true
},
"metatitle":{
required: true
},
"metadesc":{
required: true
},
"metakey":{
required: true
},
"metah1":{
required: true
},
"metaimage":{
required: true
},
"seourl":{
required: true
}
},
messages: {
"title": {
required: "Please Enter Title"
},
"content": {
required: "Please Enter Content"
},
"metatitle": {
required: "Please Enter Meta Title"
},
"metadesc": {
required: "Please Enter Meta Description"
},
"metakey": {
required: "Please Enter Meta Keywords"
},
"metah1": {
required: "Please Enter Meta H1 Tag"
},
"metaimage": {
required: "Please Enter Meta Image Title"
},
"seourl": {
required: "Please Enter SEO Url"
}
},
submitHandler: function(form) {
var myForm = document.getElementById('edit_article');
$.ajax({
type: 'post',
url: '<?php echo base_url(); ?>admin/edit_article/<?php echo $article_data[0]->ARTICLEID; ?>',
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: new FormData(myForm),
// data: $('#edit_article').serialize(),
success: function(data) {
// alert(data);
var yourval = jQuery.parseJSON(JSON.stringify(data));
var obj = jQuery.parseJSON(data);
// alert(obj);
if (obj.status == 1) {
swal("Good job!", obj.message, "success").then(function(){
window.location.reload();
});
// $('#edit_video')[0].reset();
} else {
swal({
type: 'error',
title: 'Oops...',
text: obj.message
})
}
}
});
return false;
}
});
});
</script>
答案 0 :(得分:1)
您有两个选择:
在进行ajax调用之前,将tinymce内容保存到其原始文本区域:
tinyMCE.triggerSave(true,true);
将内容追加到您的表单数据中:
var formdata = new FormData(myForm);
formdata.append("textarea", tinyMCE.getContent('content'));