Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tinymce blank content on ajax form submit?

My form uses TinyMCE to format HTML, but somehow the content is always blank on first submission. This is what I have for the submit function:

$('#commentForm').click('submit', function () {
        tinyMCE.triggerSave(true, true);
        $(this).ajaxSubmit({
            success: function (result) {
                if (result.success) {
                    $('#commentForm')[0].reset();
                    var newComment = { comment: result.comment };
                    // Append the new comment to the div
                    $('#commentTemplate').tmpl(result.comment).appendTo('#commentsTemplate');
                }
                $('#commentFormStatus').text(result.message);
            }
        });
        return false;
    });

I've added tinyMCE.triggerSave(true,true); but it doesn't seems to work. Any suggestion?

Thanks.

like image 827
Saxman Avatar asked Jan 21 '11 22:01

Saxman


2 Answers

Try to replace

tinyMCE.triggerSave(true, true);

by

tinyMCE.get("id").save();

where "id" is the ID of your textarea.

like image 167
A.Baudouin Avatar answered Sep 20 '22 05:09

A.Baudouin


$('form').on('submit', function(form){
    // save TinyMCE instances before serialize
    tinyMCE.triggerSave();

    var data = $(this).serialize();
    $.ajax({
        type:       'POST',
        cache:      false,
        url:        'inc/process.php',
        data:       data,
        success:    function(){
                        console.log("Updates have successfully been ajaxed");
        }
    });
    return false;
});
like image 41
Abdo-Host Avatar answered Sep 22 '22 05:09

Abdo-Host