这个问题对我来说很奇怪,因为它是间歇性的。我将详细介绍,所以请耐心等待。
我有一个文本区域,它被做成了一个wysiwyg编辑器http://redactorjs.com
我正在使用单击编辑功能(http://redactorjs.com/docs/examples/click-to-edit/)并使用ajax帖子保存数据。
mysql数据库字段名为"Info",并设置为"blob"类型。
现在,如果我在文本区域中输入以下文本并按save,它可能会很好地存储它。
"你好,我叫格雷格,我是一个很好的演员。我也是一个烹饪爱好者,曾在一次烹饪比赛中获得第二名。"
然后如果我点击编辑并添加
"你好,我叫格雷格,我是一个很好的演员。我也是一个烹饪爱好者,曾在一次烹饪比赛中获得第二名。我也喜欢在星期四早上游泳!"
我有时看到只有像下面这样的东西会被保存到数据库中。
"你好,我叫格雷格,我是一个很好的演员。我也是一个烹饪爱好者,曾经来过"
如果再次编辑并添加相同的文本并再次保存,则保存成功!?!?
让我给你看一些代码。。
view.php
回波信息数据
<script>
function ClickToEditInfo()
{
var info = ['formatting', '|', 'bold', 'italic', 'deleted', '|',
'unorderedlist', 'orderedlist', 'outdent', 'indent', '|',
'table', 'link', '|',
'fontcolor', 'backcolor', '|',
'alignleft', 'aligncenter', 'alignright', 'justify', '|',
'horizontalrule']
$('#info').redactor({
focus: true,
buttons: info,
wym: true,
fixed: true
});
}
function ClickToSaveInfo()
{
var html = $('#info').getCode();
var item = <?php echo $item_id; ?>;
$.ajax({
type: 'POST',
url: "ajax/clickToEditInfo.php",
data: "item_id="+item+"&html="+html,
error: function(xhr, status, error) {
console.log(error);
},
beforeSend: function() {
$("#ajax").show();
$("#ajax").html('<span class="label label-info">Saving info.. please wait</span>');
},
success: function(html){
console.log(html);
$("#ajax").html('<span class="label label-success">Saved!</span>');
$("#ajax").fadeOut(1000, function () {
$(this).hide();
});
}
});
$('#info').destroyEditor();
}
<?php
endif; // end check if user owns item
}
?>
</script>
<div id="info">
<?php echo $item->getMainField('info', $item_id); ?>
</div>
单击编辑信息.php
<?php
include_once('../classes/item.class.php');
if (!isset($_SESSION)) session_start();
$item_id = $_POST["item_id"];
$html = $_POST["html"];
$user_id = $_SESSION['jigowatt']['user_id'];
if( $item->checkUserOwns($user_id, $item_id) ) : //check user owns item
$item->clickToEditInfo($user_id, $item_id, $html);
else : // user does not own it
return false;
endif; // end check if user owns item
?>
和
item.class.php>单击编辑信息
public function clickToEditInfo($user_id, $item_id, $html) {
$stmt = parent::query("UPDATE `item_main` SET `info` = '$html' WHERE `item_id` = $item_id AND `user_id` = $user_id");
}
你能想出数据库中发布的数据被间歇性截断的原因吗?
更新:
我找到了一种可靠地复制它的方法。就像我说的是一个wysiwyg编辑。
"你好,我叫格雷格,我是一个非常好的演员。我也是一个烹饪爱好者,曾在烹饪比赛中获得第二名。"
例如,如果我突出显示竞争,然后单击超链接按钮并将其链接到谷歌。按Save,将插入以下内容。
"你好,我叫格雷格,我是一个非常好的演员。我也是一个烹饪爱好者,曾在烹饪中获得第二名"
我编辑过
<?php
include_once('../classes/item.class.php');
if (!isset($_SESSION)) session_start();
$item_id = $_POST["item_id"];
$html = $_POST["html"];
$user_id = $_SESSION['jigowatt']['user_id'];
if( $item->checkUserOwns($user_id, $item_id) ) : //check user owns item
$item->clickToEditInfo($user_id, $item_id, $html);
**echo $html;**
else : // user does not own it
return false;
endif; // end check if user owns item
?>
控制台.log(html)显示
<p>Hello my name is greg and i am a very good actor. I am also a cooking enthusiast who once came 2nd in a cooking
所以它没有发布所有的数据,这与html标签有关吗?
更新2
我已经在var html=$('#info').getCode()上完成了控制台登录并确认
<p>Hello my name is greg and i am a very good actor.</p><p>I am also a cooking enthusiast who once came 2nd place on Come dine with me :) <a href="goggle" target="">link</a> </p>
已发布,但只有
<p>Hello my name is greg and i am a very good actor.</p><p>I am also a cooking enthusiast who once came 2nd place on Come dine with me :)
在单击编辑信息中收到。php
我该怎么解决这个问题?
在通过post 发送邮件数据之前,先退出邮件数据
var html = escape($('#info').getCode());
我想我可能在发布它之前已经用html上的escape()修复了它。
http://www.w3schools.com/jsref/jsref_escape.asp
var html = $('#info').getCode();
var item = <?php echo $item_id; ?>;
var html = escape(html);