locked
Serialize HTML content RRS feed

  • Question

  • User439975351 posted

    Guys I'm trying to submit a form that has html from TinyMce editor. I'm using the following code but the HTML tags and line breaks are dumped as part of this process. How can I successfully send this back to the controller via AJAX?

    <script>
        $(function () {
            $("#regionalDescriptionButton").click(function () {
    
                $("#updateStatus").show();
    
                $.post("/Product/UpdateRegionalDescriptionById",
                    $("#regionalDescriptionForm").serialize(),
                    function (data) {
                        if (data === "null") {
                            console.log("failed");
                        } else {
                            console.log("success");
    
                            $("#updateStatus").html("<i class=\"fa fa-check\" aria-hidden=\"true\"></i>").fadeIn().delay(1000).fadeOut();
    
                        }
                    });
    
                return false;
            });
        });
    </script>

    Monday, July 16, 2018 8:41 AM

Answers

All replies

  • User-821857111 posted

    Most of these editors have a method to access the HTML, which isn't actually in your textarea. A quick google search suggests that you should configure tinyMce as follows:

    tinymce.init({
        selector: "textarea",
        setup: function (editor) {
            editor.on('change', function () {
                tinymce.triggerSave();
            });
        }
    });

    https://stackoverflow.com/questions/14393512/tinymce-textarea-and-post-form-using-ajax

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2018 9:03 AM
  • User439975351 posted

    Thanks Mike, I will give that a go and report back :)

    Monday, July 16, 2018 9:18 AM
  • User439975351 posted

    Yep that worked perfectly Mike, thanks again.

    Monday, July 16, 2018 9:28 AM