Jquery Ajax TinyMCE


Jquery Ajax TinyMCE

我有一个从MySQL表为TinyMCE动态生成的链接列表。 这工作正常,显示表中的所有链接。 现在我尝试通过 ajax 将一个值传递给 php 文件,该文件生成链接列表以根据子学科缩小查询范围:

<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>

问题是链接列表现在没有显示在TinyMCE中,可能是因为该值没有被传递。 我可以通过link_list.js.php传递 URL 字符串中的值来获得结果,因此正在发生其他事情。 要么上面的ajax调用是错误的,要么TinyMCE在编辑器加载时加载链接列表,之后列表无法更新。

仅供参考,如果这可以帮助其他人,link_list.js.php为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; ?>
);

链接列表作为选项添加到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>

如果我正确理解您的探索,当 tinyMCE 以文本区域模式运行时,您不会从 POST 上获得任何数据......

尝试添加 tinyMCE.triggerSave();

  $("#sub_discipline").change(function(){
      tinyMCE.triggerSave();
$.ajax({