2010-10-06 13 views
7

Aggiungo il contenuto in alcuni campi di input e area di testo con la funzione jQuery ajax. Solo textare utilizza TINYMCE.Come svuotare il contenuto TINYMCE dopo un'azione jax con jquery

Tuttavia dopo ajax, il testo in TINYMCE non si aggiorna e rimane.

Come posso svuotare il contenuto in TINYMCE con jquery?

Il mio codice attuale è il seguente.

//on submit event 
    $("#specformentry").submit(function(event){ 
     event.preventDefault(); 
     if(checkForm()){ 
      // var href = $(this).attr("href"); 
      submitinput.attr({ disabled:true, value:"Sending..." }); 
      //$("#send").blur(); 
      //send the post to shoutbox.php 
      $.ajax({ 
       type: "POST", 
       url: "../../Ajaxinsertspec", 
       data: $('#specformentry').serialize(), 
       complete: function(data){ 
        update_entry(); 
        specdesc.val(''); 
        datecreated.val(''); 
        detailstext.val(''); 
       // this code is supposed to empty the INYMCE content, but it does not 

        //reactivate the send button 
        submitinput.attr({ disabled:false, value:"Enter Spec" }); 
       } 
      }); 
     } 
     else alert("Please fill all fields!"); 
     //we prevent the refresh of the page after submitting the form 
     return false; 
    }); 

E la segue è una parte di HTML

<div id="enterlabel"><label for="spec_details">Click me to enter Spec Details</label></div> 
<div style="display: block;" id="textarea"> 
<textarea style="display: none;" name="spec_details" cols="90" rows="12" id="detailstext"></textarea> 
<span class="mceEditor defaultSkin" id="detailstext_parent"> 
    <table style="width: 100px; height: 100px;" class="mceLayout" id="detailstext_tbl" cellpadding="0" cellspacing="0"> 
     <tbody><tr class="mceFirst"> 
      <td class="mceToolbar mceLeft mceFirst mceLast"><a href="#" accesskey="q" title="Jump to tool buttons - Alt+Q, Jump to editor - Alt-Z, Jump to... 
... 

risposta

14

Non è necessario svuotare jQuery TinyMCE. Ottenere l'istanza TinyMCE da id e impostare il contenuto da '' (uguale vuoto) utilizzando

// l'id del primo editorinstance della pagina si trova in tinymce.editors [0] .id

var tinymce_editor_id = 'my_tinymce_id'; 
tinymce.get(tinymce_editor_id).setContent(''); 
+0

Grazie Ha risolto il problema ..

+0

ottimo per essere stato di aiuto – Thariama

2

Prova con codice qui sotto

if (typeof(tinyMCE) != 'undefined') { 
    $('#edit-comment').val(''); // Removes all paragraphs in the active editor 
} 
8

Questo ha funzionato per me:

tinyMCE.activeEditor.setContent(''); 

Soprattutto se è l'unico editor esistente nella tua pagina.

+0

quanto basta per il mio caso, non di più! :) – lean

Problemi correlati