Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Combine Ajax content loader with editor

This function places 'Hello World' inside my rich text editor (TinyMCE)

      function ajaxLoad() {
      var ed = tinyMCE.get('elm1');
      ed.setContent('Hello World');
      }

This line of code places the content of test.php into an empty div
      ajax_loadContent('divID','external/info.php');

How can I combine these, so that I can place the content of test.php into the editor?

This does NOT work:
      function ajaxLoad() {
      var ed = tinyMCE.get('elm1');
      ed.setContent(ajax_loadContent(ed,'external/info.php'));
      }
edit.zip
Avatar of pellep
pellep
Flag of Sweden image

TinyMCE doesn't really work that way. When you initialize the editor instance, it replaces the div/textarea so you're not supposed to interact with the content outside of the tinyMCE framwork.

Try this and see if it works
 
function ajaxLoad() {
var ed = tinyMCE.get('elm1');
ajax_loadContent(ed.getElement() ,'external/info.php')); // set content on underlying div
ed.load(); //reload editor from underlying div
      }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pellep
pellep
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

ASKER

Thanks, pellep.

Your answer had two parts.

You explained that the content in the editor iframe MUST be reloaded after this is done.

And you explained that the code presumes the content is in a div, not a textarea.

I have asked a related question here:

https://www.experts-exchange.com/questions/23898620/AJAX-Works-with-div-but-not-textarea.html
Avatar of whspider
whspider

Hi hankknight,

i am in need of the same...can u give me the link from where you got this editor....i to want to load
different values to the editor based on a select ooption uisng ajax
whspider, I do not understand what you need.  The editor is TinyMCE.
http://tinymce.moxiecode.com/