Javascript 带有Laravel和jQuery的CKEditor setData()

Javascript 带有Laravel和jQuery的CKEditor setData(),javascript,php,jquery,laravel,ckeditor,Javascript,Php,Jquery,Laravel,Ckeditor,我在将数据设置到现有的CKEditor编辑器中时遇到问题 时间很长,但我不知道出了什么问题 问题是,我正在从数据库中获取html数据,但当我反复刷新页面时,系统有时能够,有时无法从当前CKEditor文本区域的数据数组中设置数据加载值 html文件: Routes.php文件 myController.php文件 如有任何帮助,我们将不胜感激。首先,请检查出现问题时您的请求会产生什么结果console.log数据。第二,确保在那一刻获得数据。顺便问一下,为什么要在editor.setData之前

我在将数据设置到现有的CKEditor编辑器中时遇到问题

时间很长,但我不知道出了什么问题

问题是,我正在从数据库中获取html数据,但当我反复刷新页面时,系统有时能够,有时无法从当前CKEditor文本区域的数据数组中设置数据加载值

html文件:

Routes.php文件

myController.php文件


如有任何帮助,我们将不胜感激。

首先,请检查出现问题时您的请求会产生什么结果console.log数据。第二,确保在那一刻获得数据。顺便问一下,为什么要在editor.setData之前调用它?@oleq我尝试了很多组合,所以就这样离开了。我也在editor.setData之后尝试了updateElement。但是没有改变。我要试试这个控制台。日志数据的东西。请参考,我可以使用alertdata['stringValue']获取数据。因此,我可以获取数据,但无法在CKEditor中设置。
<textarea id="myTextAreaID" name="myTextArea"></textarea>
<script type="text/javascript">
    $(function () {
        var myEditor = $('#myTextAreaID');
        myEditor.ckeditor({
        height: 200,
        extraPlugins: 'wordcount',
        maxLength: 2500,
        toolbar: 'TinyBare',
        toolbar_TinyBare: [
             ['Bold','Italic','Underline'],
             ['Undo','Redo'],['Cut','Copy','Paste'],
             ['NumberedList','BulletedList','Table'],['CharCount']
        ]
        }).ckeditor().editor.on('key', function(obj) {
            if (obj.data.keyCode === 8 || obj.data.keyCode === 46) {
                return true;
            }
            if (myEditor.ckeditor().editor.document.getBody().getText().length >= 2500) {
                alert('You have reached the maximum value.');
                var pureHtmlValue = $('#myTextAreaID').ckeditor().editor.document.getBody().getHtml();
                var subbed_html = html_substr(pureHtmlValue, 0, 1000); $('#myTextAreaID').ckeditor().editor.document.getBody().setHtml(subbed_html);
                return false;
            }
        });
    });

    //using this one to cut extra string values without destroying the HTML tags.
    function html_substr( str, start ,count ) {

    var div = document.createElement('div');
    div.innerHTML = str;

    walk( div, track );

    function track( el ) {
        if( count > 0 ) {
            var len = el.data.length;
            if(start<=len){
                el.data = el.substringData(start,len);
                start=0;
            } else{
                start-=len;
                el.data = '';
            }
            len = el.data.length;
            count -= len;
            if( count <= 0 ) {
                el.data = el.substringData( 0, el.data.length + count );
            }

        } else {
            el.data = '';
        }
    }

    function walk( el, fn ) {
        var node = el.firstChild;
        do {
            if( node.nodeType === 3 ) {
                fn(node);
            } else if( node.nodeType === 1 && node.childNodes && node.childNodes[0] ) {
                walk( node, fn );
            }
        } while( node = node.nextSibling );
    }
    return div.innerHTML;
}
</script>
$(document).ready(function(){
    $('#myBootstrapTab a').on('load', function (e) {
        e.preventDefault();
        $(this).tab('show');
    },onLoadMyFunction());
}

function onLoadMyFunction(){
    $.post("postToGetValuesFromDBRoute",function(data){
       CKEDITOR.instances['myTextAreaID'].updateElement();
       //myBindedData is in the next file
       CKEDITOR.instances['myTextAreaID'].setData(data['myBindedData']);
    });
}
Route::post('postToGetValuesFromDBRoute', array(
    'uses' => 'myController@postToGetValuesFromDBRoute',
    'as' => 'postToGetValuesFromDBRoute'
));
public function postToGetValuesFromDBRoute(){
   $myModelInstance = MyModel::where('id', '=', 'someValue'))->first();

   Input::merge(array(
          myBindedData => $myModelInstance['myFieldFromEloquentModel'];
   ));
   return Response::json(Input::all());
}