Search code examples
javascriptjqueryajaxckeditor

CKeditor populate dialog select with Ajax


I am trying to populate my CKeditor dialog selectbox with ajax. The following is from my plugin.js file:

...
{
    type : 'select',
    id : 'style',
    label : 'Style',
    setup : CKEDITOR.ajax.post(  '.../ckeditor/plugins/simpleLink/ajax.php', JSON.stringify( { foo: 'bar' } ), 'application/json', function( data ) { 
            console.log( data);
    }),
    items : [ ['--- Select something ---', 0] ],
    commit : function( data )
    {
        data.style = this.getValue();
    }
}
...

The ajax output looks like this:

["Basketball","basketball"],["Baseball","baseball"],["Hockey","hockey"]

I am really wondering how to get the output INTO the "items". From my point of view I tried everything. Can someone help me?


Solution

  • Found a workaround. For anyone having the same problem - here is my way of solving it:

    plugin.js:

    This code before "CKEDITOR.plugins.add( 'PLUGINNAME', {..."

    jQuery.extend({
    getValues: function(url) {
        var result = null;
        $.ajax({
            url: url,
            type: 'get',
            dataType: 'json',
            async: false,
            success: function(data) {
                result = data;
            }
        });
       return result;
    }
    });
    var results = $.getValues('.../ckeditor/plugins/PLUGINNAME/ajax.php');
    

    This is the code for the select box

    {
        type : 'select',
        id : 'style',
        label : 'Style',
        setup : '',
        items : results,
        commit : function( data )
        {
            data.style = this.getValue();
        }
    }