How can I put a jquery variable inside FormData?
Example:
I have a CKEDITOR, however I am not able to save in the database, but I am using the ajax send format, which I found on a website, to upload images, and this way, uses FormData, however I do not know how to do the CKEDITOR data, to be registered in the database.
Follow the code:
$(function () {
$("#load").hide();
var enviando_formulario = false;
$('#form-post').submit(function (e) {
e.preventDefault();
var post_content = CKEDITOR.instances['post_content'].getData();
var obj = this;
var form = $(obj);
console.log(obj);
var submit_btn = $('#form-post :submit');
var submit_btn_text = submit_btn.val();
var dados = new FormData(obj);
console.log(dados);
function volta_submit() {
submit_btn.removeAttr('disabled');
submit_btn.val(submit_btn_text);
enviando_formulario = false;
}
if (!enviando_formulario) {
$.ajax({
beforeSend: function () {
enviando_formulario = true;
submit_btn.attr('disabled', true);
submit_btn.val('Enviando...');
$("#load").show();
$('.error').remove();
},
url: form.attr('action'),
type: form.attr('method'),
data: dados,
processData: false,
cache: false,
contentType: false,
success: function (data) {
$('.info').remove();
volta_submit();
if (data > 0) {
$('#load').hide();
$('#form-grupo input').val("");
$('#form-grupo textarea').val("");
} else {
submit_btn.before('<div class="alert alert-danger error">' + data + '</div>');
}
$('.suc').remove();
},
error: function (request, status, error) {
volta_submit();
alert(request.responseText);
}
});
}
return false;
});
});