开发者

TinyMCE editor in Ajax form using jQuery plugin

I have ajax form (http://jquery.malsup.com/form/) and I use jQuery plugin to install my TinyMCE editor. But I cannot get textarea content in ajax request. This is because its in TinyMCE editor iframe. I tried several tutorials from google, but all failed to work for me. Editor shows up, but when I send ajax request, it fails to get edited textarea content.

Here is how I install TinyMCE editor, but this fai开发者_高级运维ls

$("textarea.tinymce").tinymce({         
    script_url : tinymceUrl,
    mode : "none",
    theme : "simple",
    setup : function(ed) {
        ed.onChange.add(function() {
            tinyMCE.triggerSave(true,true);
        });
    }
});


The onChange event is "iffy" at best. I recently went through this with a project that I'm on and had to bind the focus & blur events ... it was not pretty. In my setup handler I did the following. I've removed the code that is specific to my project and put a comment in where to do the save.

ed.onPostRender.add(function(editor, cm) {
    // Register focus and blur events on BOTH the window and the doc, this way it works properly in
    // IE, Firefox & Chrome
    tinymce.dom.Event.add(editor.getWin(), 'focus', function(e) { });
    tinymce.dom.Event.add(editor.getWin(), 'blur', function(e) { /* save on blur */ });
    tinymce.dom.Event.add(editor.getDoc(), 'focus', function(e) { });
    tinymce.dom.Event.add(editor.getDoc(), 'blur', function(e) { /* save on blur */ });
});

On a side note, I noticed that you're calling the editor manager (tinyMCE) with triggerSave(true, true). I don't see that in the 3.3.9.2 API so I don't know what is attempting to be done there. In the above code, a handle to the editor (e) is being passed and the method e.save() can be called to perform the save and store it in the textarea field that is being decorated by tinyMCE.

Hope that helps.


As Dave G already states the API link is old (and i was wondering about the call of triggerSave).

Please try

tinyMCE.triggerSave();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜