I’m posting HTML content via AJAX to PHP. During debugging process i see that ajax posts whole content from editor. But when i’m checking my db I see 40-50% of sent content. Filtering sent data with following function in php. My database field type is text with 0 length.
function html($data, $db)
{
$data = htmlentities($data);
$data = $db->escape_string($data);
return $data;
}
No success. But when i’m trying to post standard text content (none-html) it posts whole content into db table. How to deal with that problem? Any suggestions?
JS
function postViaAjax(autosaveMode) {
var name = $("#name").val();
var title = $("#title").val();
var menu = $("#menu").val();
var parentcheck = $(".parentcheck:checked").val();
var id = $("#id").val();
if (parentcheck == 0) {
var parent = parentcheck;
} else {
var parent = $("#parent").val();
}
var content = CKEDITOR.instances['content'].getData();
var dataString = 'name=' + name + '&title=' + title + '&menu=' + menu + '&parentcheck=' + parentcheck + '&id=' + id + '&parent=' + parent + '&content=' + content;
$.ajax({
type: "POST",
url: "processor/dbadd.php",
data: dataString,
dataType: "json",
success: function (result, status, xResponse) {
var message = result.msg;
var err = result.err;
var now = new Date();
if (message != null) {
if (autosaveMode) {
$('#submit_btn').attr({
'value': 'Yadda saxlanıldı ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
});
} else {
$.notifyBar({
cls: "success",
html: message + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
});
}
}
if (err != null) {
$.notifyBar({
cls: "error",
html: err
});
}
}
});
};
Most likely because you need to escape your “content” when you’re posting it.
Try
or
Before appending it to the dataString