How to use TinyMCE with JQuery?

0

I'm trying to use TinyMCE with JQuery but without success, it sends the textarea data without the formatting, if I try without JQuery it works, does JQuery not accept the html tags inserted by TinyMCE?

Example html part:

        <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"]);
    
asked by anonymous 13.10.2016 / 15:27

1 answer

0

I'm sorry, the solution is very simple, just add the line

  

tinyMCE.triggerSave ();

before

  

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

And it works!

    
13.10.2016 / 15:45