weixin_33688840 2013-01-29 07:13 采纳率: 0%
浏览 39

jQuery Ajax TinyMCE

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>
  • 写回答

1条回答 默认 最新

  • bug^君 2013-01-29 15:16
    关注

    If I'm understanding your questing correctly you are getting no data on POST from the tinyMCE when it is running in textarea mode...

    try adding tinyMCE.triggerSave();

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

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题