I'm using summernote html text editor and its Insert Image feature. (When user enter an image, I'm sending it to my backend and replace user's img url with mine)
Example:
User input: http://example.com/image.jpg -> upload this image to Amazon S3 -> Update summernote text area's img src="" (mydomain.com/blabla.jpg).
Above logic working well. There is no problem here.
Then I want to send this texarea to my backend php script for db stuff.
But When I serilize and submit form. Ajax sending user's image url. Not replaced image url.
IMAGE UPLOAD
/*GET USER'S IMAGE URL AND SEND IT TO BACKEND. UPLOAD IT, THEN RAPLACE IT'*/
/*THIS PART IS WORKING CORRECTLY */
$('button[data-original-title="Picture"]').click(function(){
// Set handler on Inset Image button when dialog window is opened
$('.modal-dialog .note-image-btn').on('click', function(e) {
var imageUrl = $('.modal-dialog .note-image-url').val();
var currentTitle = $("#title").val().trim();
if(currentTitle.length == 0){
currentTitle = "";
}
$.ajax({
url: "upload.php",
data: "url="+encodeURIComponent(imageUrl)+"&title="+encodeURIComponent(currentTitle),
type: "POST",
dataType: 'json',
success: function(data) {
if (typeof data[0] === 'string') {
$('img[src="' + imageUrl + '"]').attr('src', data);
} else {
// What to do if image downloading failed
window.alert('oops');
}
},
error: function () {
/* console.log("error");*/
}
});
});
});
FORM SUBMIT WITH AJAX (PROBLEM IS HERE I THINK)
/* SEND SERIALIZED FORM DATA TO BACKEND */
/* PROBLEM IS HERE. $("#form").serialize() CAN'T GET replaced IMAGE URL. */
$("#submitButton").on("click",function () {
$.ajax({
url: "save-article.php",
data: $("#form").serialize(),
type: "POST",
success: function(data) {
if(data === "success"){
$(".messageBox").html('<div class="alert alert-success ic">Thanks, you are redirecting</div>');
}else if(data === "fail"){
$(".messageBox").html('<div class="alert alert-danger ic">There was an error</div>');
}
},
error: function (e) {
console.log(e);
}
});*/
});
How can I get changed summernote text area's value and serialize it?