0

Am trying to pass wysiwyg boostrap editor content through ajax to a php page but the content of the editor returns as [object Object] i dont know what am doing wrong or what am not doing at all this is my code

<form class="form-horizontal form-label-left" novalidate>


                   <div class="btn-toolbar editor" data-role="editor-toolbar" data-target="#editor-one">
                <div class="btn-group">
                  <a class="btn dropdown-toggle" data-toggle="dropdown" title="Font"><i class="fa fa-font"></i><b class="caret"></b></a>
                  <ul class="dropdown-menu">
                  </ul>
                </div>

                <div class="btn-group">
                  <a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="fa fa-text-height"></i>&nbsp;<b class="caret"></b></a>
                  <ul class="dropdown-menu">
                    <li>
                      <a data-edit="fontSize 5">
                        <p style="font-size:17px">Huge</p>
                      </a>
                    </li>
                    <li>
                      <a data-edit="fontSize 3">
                        <p style="font-size:14px">Normal</p>
                      </a>
                    </li>
                    <li>
                      <a data-edit="fontSize 1">
                        <p style="font-size:11px">Small</p>
                      </a>
                    </li>
                  </ul>
                </div>

                <div class="btn-group">
                  <a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="fa fa-bold"></i></a>
                  <a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="fa fa-italic"></i></a>
                  <a class="btn" data-edit="strikethrough" title="Strikethrough"><i class="fa fa-strikethrough"></i></a>
                  <a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="fa fa-underline"></i></a>
                </div>

                <div class="btn-group">
                  <a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="fa fa-list-ul"></i></a>
                  <a class="btn" data-edit="insertorderedlist" title="Number list"><i class="fa fa-list-ol"></i></a>
                  <a class="btn" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="fa fa-dedent"></i></a>
                  <a class="btn" data-edit="indent" title="Indent (Tab)"><i class="fa fa-indent"></i></a>
                </div>

                <div class="btn-group">
                  <a class="btn" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="fa fa-align-left"></i></a>
                  <a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="fa fa-align-center"></i></a>
                  <a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="fa fa-align-right"></i></a>
                  <a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="fa fa-align-justify"></i></a>
                </div>

                <div class="btn-group">
                  <a class="btn dropdown-toggle" data-toggle="dropdown" title="Hyperlink"><i class="fa fa-link"></i></a>
                  <div class="dropdown-menu input-append">
                    <input class="span2" placeholder="URL" type="text" data-edit="createLink" />
                    <button class="btn" type="button">Add</button>
                  </div>
                  <a class="btn" data-edit="unlink" title="Remove Hyperlink"><i class="fa fa-cut"></i></a>
                </div>

                <div class="btn-group">
                  <a class="btn" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="fa fa-picture-o"></i></a>
                  <input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
                </div>

                <div class="btn-group">
                  <a class="btn" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="fa fa-undo"></i></a>
                  <a class="btn" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="fa fa-repeat"></i></a>
                </div>
              </div>
              <div id="editor-one" class="editor-wrapper">

              </div>

             <input type="hidden" name="content" id="form-content">
                  <div class="ln_solid"></div>
                  <div class="form-group">
                    <div class="col-md-6 col-md-offset-3">
                      <button type="submit" class="btn btn-primary">Cancel</button>
                      <button  type="submit" name="sunmit" class="btn btn-success">Submit</button>
                    </div>
                  </div>

                </form>

and this is my ajax

$(function () {

    $('form').on('submit', function (e) {

      e.preventDefault();

     document.getElementById("load").style.display = "block";
     var textarea = $('#form-content').val($('#editor-one').html().value);
        textarea = escape(textarea);
      $.ajax({
        type: 'post',
        url: 'edit.php',
        data: $('form').serialize() + '&ins=editco' + '&val=<?php echo $value; ?>' + '&html='+textarea,
         success: function(data)
        {
            document.getElementById("load").style.display = "none";
            jQuery('#get_result').html(data).show();
        }
      });

    });

  });
nsikak
  • 111
  • 1
  • 13
  • What does `edit.php` do? Your question is not Minimal, Complete, and Verifiable. See: https://stackoverflow.com/help/mcve Yes, writing a good question can take a bit of time. It might even help you to find the problem yourself. If you don't you have a good question to ask. – KIKO Software May 13 '17 at 19:52
  • edit.php is the php file am passing it to, for inserting into database. the problem does not relate to edit.php. when it gets to edit.php with post it returns object object also when i use alert to see what it returns before going to edit.php it shows object object. edit is not the problem @KIKOSoftware – nsikak May 13 '17 at 20:12
  • this line returns [object Object] `var textarea = $('#form-content').val($('#editor-one').html().value);` – nsikak May 13 '17 at 20:29
  • Thanks for the last comment, that was helpful. If I assume you're using this editor (https://mindmup.github.io/bootstrap-wysiwyg) you can access the content of the editor with this jquery: `var textarea = $('#editor-one').html();`. If you're using another editor, this might not work. – KIKO Software May 14 '17 at 07:44
  • thanks a lot it worked @KIKOSoftware – nsikak May 14 '17 at 11:42

0 Answers0