TinyMCE自定义按钮按问题

时间:2009-12-13 11:39:00

标签: php wordpress tinymce

我正在使用TinyMCE并希望执行php脚本获取输出并发布输出 我正在尝试使用预先填充php脚本的数据插入我的代码。

有人可以帮我解决这个问题。我是一个JavaScript新手..

这是我插入没有数据的单个实例的代码。 (其余代码直接来自文档api上的示例)

///////////////////////////////////////////////////////////////////////////////
            ed.addCommand('mceCommandHere', function() {
            ed.execCommand('mceInsertContent',false,'[CODEHERE ="" URL ="" Title=""]'); 
            });
            ed.addButton('CommandHere', {
                title : 'Add Subscriptions',
                cmd : 'mceCommandHere',
                image : url + '/PictureHere.png'
            });
            ed.onNodeChange.add(function(ed, cm, n) {
                cm.setActive('CommandHere', n.nodeName == 'IMG');
            });
            ///////////////////////////////////////////////////////////////////////////////

2 个答案:

答案 0 :(得分:1)

我明白了! YEAH!它只让我看了2天!

            ///////////////////////////////////////////////////////////////////////////////
        ed.addCommand('mceCommandHere', function() {
            var mydata;
          tinymce.util.XHR.send
          ({
                   url :  url + "/CommandHere.php",
                   content_type : "text/html",
                   type : "GET",
                  data : tinymce.util.JSON.serialize({
                       param1 : "TinyMCE"
                   }),
                   async : false,
                   scope : ed,

                   success : function( data, req, o ) {
                         mydata = data;
                   },

                   error : function( type, req, o ){
                       alert('Something Went Wrong, Please Check your Installation.  Error Type: '+ type +' Error Status: '+req.status ); 
                   }
          });

        ed.execCommand('mceInsertContent',false, mydata );  
        });
        ed.addButton('CommandHere', {
            title : 'CommandHere',
            cmd : 'mceCommandHere',
            image : url + '/CommandHere.png'
        });
        ed.onNodeChange.add(function(ed, cm, n) {
            cm.setActive('CommandHere', n.nodeName == 'IMG');
        });
        ///////////////////////////////////////////////////////////////////////////////

答案 1 :(得分:0)

不确定你的意思,但是php总是在js之前执行,除非你有一些ajax在继续。 因此,您可以将数据库内容直接插入tinymce

使用的textarea标记中
 <textarea name="content"><?php echo $my_data ?></textarea>