jqueryajaxmedium-editor

Getting blank AJAX data from MediumEditor div


I originally had a <textarea name="userWords"> that correctly triggered a jquery call and sent data. But I needed nicer text editing, so I'm trying to use MediumEditor instead of the textarea. I have the following html:

<form method="post" action="/userWords" enctype="multipart/form-data"  data-id="{{uniqueId}}" id="{{uniqueId}}-userWords">
    <div name="userWords" id="ThisBox" class="editable" contenteditable="true"></div>
</form>

And the following AJAX used to work with textarea but now no longer works:

 var Id = $(this).data('id');
 var data = new FormData($("#" + Id + "-userWords")[0]);

        var ajaxOptions = {
            url: '/userWords',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function(res) {
              //...do stuff
            }
        };

        $.ajax(ajaxOptions);

Basically, the data is null. Is there something I'm missing?


Solution

  • Try the following:

     var textdata = $('#'+ThisBox).val();
     var my_object = {"ThisBox": textdata};
    
            var ajaxOptions = {
                url: '/userWords',
                data: my_object,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                success: function(res) {
                  //...do stuff
                }
            };
    
            $.ajax(ajaxOptions);