I have a dynamically generated link list from MySQL table for TinyMCE. This works OK showing all links in the table. Now I'm trying to pass a value via ajax to the php file that generates the list of links to narrow the query based on the sub-discipline:
<script type="text/javascript">
$(document).ready(function() {
$("#sub_discipline").change(function(){
$.ajax({
url: "../scripts/tiny_mce/lists/link_list.js.php",
type: "post",
data: {
sub_discipline : $('#sub_discipline').val()
},
success: function(data){
}
});
});
}
);
</script>
Problem is that the list of links is not now showing in TinyMCE, probably because the value isn't being passed. I can get results with link_list.js.php passing the value in the URL string, so something else is happening. Either the ajax call above is wrong, or TinyMCE loads the list of links when the editor loads and the list can't be updated afterwards.
FYI, in case this can help others, link_list.js.php which works just fine creating the list of links for TinyMCE:
<?php Header("content-type: application/x-javascript"); ?>
<?php
require_once('../../../connection/connect.php');
mysql_select_db($database, $connection);
$sub_discipline = $_POST['sub_discipline'];
$query = "SELECT link_title, url FROM link WHERE sub_discipline_fk = '$sub_discipline'";
$result = mysql_query($query, $connection) or die(mysql_error());
$links = array();
while($row = mysql_fetch_assoc( $result)){
$links[$row['link_title']] = $row['url'];
}
$o = null;
$count = count($links);
$i = 1;
foreach($links as $text => $url){
$o .= sprintf(('["%1$s", "%2$s"]'),
$text,
$url
);
if($i < $count)
$o .= ',';
$i++;
}
?>
var tinyMCELinkList = new Array(
<?php echo $o; ?>
);
Link list is added as an option in the tinyMCE.init:
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
// Theme options
theme_advanced_buttons1 : "print,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,formatselect,fontsizeselect,|,forecolor,backcolor",
theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,fullscreen",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,emotions,iespell,media,|,ltr,rtl",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Skin options
skin : "o2k7",
skin_variant : "silver",
// Drop lists for link/image/media/template dialogs
external_link_list_url : "../scripts/tiny_mce/lists/link_list.js.php",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
});
</script>