0
How can I put a jquery variable inside Formdata?
Example:
I have a CKEDITOR, but I am not able to save in the database, but I am using the format of sending with ajax, I found on a website, to upload images, and this way, uses Formdata, however I do not know how to do for the data of CKEDITOR, be registered in the database.
Follows 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;
});
});