I have an issue saving summernote value in DB using ajax but when i dont use ajax everything is working.
to make it clear.
<?php
include 'db.php';
$db=new db;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
if($_POST['act']=='save'){
$content=$_POST['content'];
$id=25;
$query="UPDATE content SET content=? WHERE id=?";
$db->execquery($query, 'si', array($content, $id));
echo json_encode(array("response"=>'success'));
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>summernote</title>
<!-- include jquery -->
<script src="//code.jquery/jquery-1.11.3.min.js"></script>
<!-- include libraries BS3 -->
<link rel="stylesheet" href="//netdna.bootstrapcdn/bootstrap/3.0.1/css/bootstrap.min.css" />
<script type="text/javascript" src="//netdna.bootstrapcdn/bootstrap/3.0.1/js/bootstrap.min.js"></script>
<!-- include summernote -->
<link rel="stylesheet" href="../dist/summernote.css">
<script type="text/javascript" src="../dist/summernote.js"></script>
<script type="text/javascript">
$(function() {
$('.summernote').summernote({
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
]
});
$('form').on('submit', function (e) {
e.preventDefault();
content=$('.summernote').summernote('code');
data='act=save&content='+content;
$.ajax({
type: "POST",
dataType: "JSON",
data: data,
})
.fail(function(e){
alert(e.response);
})
.done(function(data){
if(data.response=='success'){
alert('success!');
}
});
});
});
</script>
</head>
<body>
<form action="#" novalidate>
<div class="form-group">
<label for="input">Text</label>
<textarea class="form-input" id="input"></textarea>
</div>
<div class="form-group">
<label for="contents">Contents</label>
<textarea name="text" class="summernote" id="contents" title="Contents"></textarea>
</div>
<button type="submit" class="btn btn-default">submit</button>
</form>
</body>
</html>
Anyway when I just type simple texts in summernote the values are being saved but when I paste some text from msword something like that the values being saved are cut.
I tried something that when I press submit I am also putting the summernote values into an extra textarea then when I paste the values manually in DB everything is good. I also tried copying the codeview values then paste in DB manually then it's good also. Please help.
Thanks in advance!
I have an issue saving summernote value in DB using ajax but when i dont use ajax everything is working.
to make it clear.
<?php
include 'db.php';
$db=new db;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
if($_POST['act']=='save'){
$content=$_POST['content'];
$id=25;
$query="UPDATE content SET content=? WHERE id=?";
$db->execquery($query, 'si', array($content, $id));
echo json_encode(array("response"=>'success'));
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>summernote</title>
<!-- include jquery -->
<script src="//code.jquery./jquery-1.11.3.min.js"></script>
<!-- include libraries BS3 -->
<link rel="stylesheet" href="//netdna.bootstrapcdn./bootstrap/3.0.1/css/bootstrap.min.css" />
<script type="text/javascript" src="//netdna.bootstrapcdn./bootstrap/3.0.1/js/bootstrap.min.js"></script>
<!-- include summernote -->
<link rel="stylesheet" href="../dist/summernote.css">
<script type="text/javascript" src="../dist/summernote.js"></script>
<script type="text/javascript">
$(function() {
$('.summernote').summernote({
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']]
]
});
$('form').on('submit', function (e) {
e.preventDefault();
content=$('.summernote').summernote('code');
data='act=save&content='+content;
$.ajax({
type: "POST",
dataType: "JSON",
data: data,
})
.fail(function(e){
alert(e.response);
})
.done(function(data){
if(data.response=='success'){
alert('success!');
}
});
});
});
</script>
</head>
<body>
<form action="#" novalidate>
<div class="form-group">
<label for="input">Text</label>
<textarea class="form-input" id="input"></textarea>
</div>
<div class="form-group">
<label for="contents">Contents</label>
<textarea name="text" class="summernote" id="contents" title="Contents"></textarea>
</div>
<button type="submit" class="btn btn-default">submit</button>
</form>
</body>
</html>
Anyway when I just type simple texts in summernote the values are being saved but when I paste some text from msword something like that the values being saved are cut.
I tried something that when I press submit I am also putting the summernote values into an extra textarea then when I paste the values manually in DB everything is good. I also tried copying the codeview values then paste in DB manually then it's good also. Please help.
Thanks in advance!
Share Improve this question asked Dec 15, 2016 at 2:49 dmacdmac 531 silver badge4 bronze badges1 Answer
Reset to default 5I had the same problem and I fixed it with:
Javascript
content = encodeURIComponent($('.summernote').summernote('code'));
PHP
urldecode($_POST[content])