【发布时间】:2012-07-03 23:31:34
【问题描述】:
我的问题是CKEditor,它在我提交数据时添加了\n。
要获取我正在使用的数据:
CKEDITOR.instances['contentBox'].getData()
在数据库中提交后的数据示例:
<p>\n Heloo<br />\n How are you?</p>\n
<p>\n Another Subject<br />\n My name is Luis</p>\n
一切都很好,只是想取消\n。我不想使用 REGEX 或其他 PHP 函数来删除它。我更喜欢通过 CKEditor 的配置解决方案。
编辑 ::
CKEditor不是问题(看David Mulder的回答)。
我创建的 Ajax 代码(可能是问题所在):
$('#edit').live('click', function() {
if ($("#formValue").valid())
{
$('.simplebox').slideUp(200, function() {
$('body').animate({scrollTop:140}, 350, function() {
$('#loading-edit').slideDown(300, function() {
$.ajax({
type: "POST",
dataType: "json",
url: "../new_lesson_proccess/",
data: getDataToPost(),
success: function(data){
if (data.success == true)
{
$('#loading-edit').fadeOut(200, function() {
$('.name_news_success').html($('input[name=name]').val());
$('#successfull-edit').fadeIn(200);
});
}
}
});
});
});
});
}
})
function getDataToPost()
{
var value = CKEDITOR.instances['valuecontent'].getData();
return {
id: $('input[name=news_id]').val(),
tags : $('#tags').textext()[0].tags()._formData,
name: $('input[name=name]').val(),
content: value
}
}
这里有什么问题?
编辑 2 ::
我正在使用CodeIgniter 框架。
部分控制器:
public function new_lesson_proccess()
{
// # POST to Array
$data = array(
'content' => $this->input->post('content', FALSE)
);
$dataExport = array(
'success' => $this->lessons_model->news_lesson($data)
);
echo json_encode($dataExport);
}
部分模型lessons_model:
function new_lesson($data)
{
$dataInsert = array(
'content' => mysql_real_escape_string($data['content'])
);
if ($this->db->affected_rows($this->db->insert('web_lessons', $dataInsert)) == 1)
return true;
else
return false;
}
编码:UTF-8
数据库中的字段content定义为TEXT
我删除了一些验证代码等,因为它并不重要。
【问题讨论】:
-
你能展示你在数据库中处理和存储数据的部分吗?字符 13 只是 \n 但如果它们在数据库中显示为文字 \n。可能是您处理数据的方式有问题。
-
已添加。我没有看到代码有任何问题,但也许我遗漏了一些东西..
-
验证码是否改变$data['content']?如果打开了magic_quotes,我想知道它可能会导致\n 字符与mysql_real_escape_string 结合使用。不确定。但它开启了吗?
-
我已经使用JSLint 的建议清理了您的 AJAX 代码。如果这有帮助,请告诉我。干杯!
标签: javascript ckeditor