I am using tinyMCE for WordPress.
Which is the way to load text from server via AJAX?
Until now I have:
php:
<?php echo the_editor($_POST ? $_POST['content'] : '', $id = 'content'); ?>
javascript (which is failing…):
$("select[name='tpl']").live("change", function(e) {
var file = $(this).val();
var loadUrl = varsJs.WORDPRESS_PLUGIN_URL + "/templates/" + file;
$.get(loadUrl, function(result) {
$("#content").val(result);
});
});
The variable result
is loaded with the desired text. No problem with that. But how pass this content to the tinyMCE?
Note:
varsJs
is the second parameter ofwp_localize_script
function used to pass data fromphp
tojavascript
. Really no needed in this precise issue but useful to know it.Try this code, where ‘content‘ is your field #ID
this way and once tinymce is also loaded in current html,
you will reinit only one field, the one you received from Ajax Request.
also set this code before ajax saving Call