How to use Tinymce with Jquery?

Asked

Viewed 263 times

0

I’m trying to use Tinymce with Jquery but unsuccessfully, it sends the textarea data without formatting, if I try without Jquery it works, will Jquery not accept the html tags inserted by Tinymce?

Example part of html:

        <script src="/tinymce/js/tinymce.min.js"></script>
        <script>
              $(document).ready(function () {

                  $("#btngravar").on("click", function () {

                     var form = $(this).parents("form");
                     var data = $(form).serializeArray();

                     $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "pagina.php",
                        data: data,
                        complete: function (json, status) {
                            // alert("passou");
                        },
                        success: function (json, status) {
                            alert("gravou");
                        },
                        error: function (json, status) {
                            alert("erro");
                        }
                    });
                });

                tinymce.init(
                        {
                            mode: "exact",
                            elements: "texto"
                        });
            });
        </script>
    ...

<form action="pagina.php" method="post">
    <textarea id="texto" name="texto"></textarea>
    <input type="button" id="btngravar" value="gravar"/>
</form>

Example part of PHP:

echo($_POST["texto"]);

1 answer

1

I’m sorry guys, the solution is quite simple, just add the line

tinymce.triggerSave();

before

var form = $(this). parents("form");

and it works!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.