KindEditor异步加载和异步保存

DATE: 2015-08-28 / VIEWS: 1732


<script>
var app_id = 17,editor='';
jQuery(document).ready(function ($) {
    $.ajax({
        'type':'GET',
        'url':'/index.php?g=Api&m=News&a=get_info&app_id='+app_id,
        'data':{id:97},
        'dataType':'json',
        success:function(msg){
            $('textarea[name="content"]').html(msg.data.info)
            editor = KindEditor.create('textarea[name="content"]',{
                afterBlur: function(){this.sync();}
            });
        }
    })

    $("#save").on('click', function() {
        $.post('/index.php?g=Api&m=News&a=save_new_one',{
            "app_id":app_id,
            "id":"97",
            "title":"ceshi",
            "info":editor.html()
        }, function(data) {
            console.log(data)
        },'json');
    });

}) 
</script>


重点是editor变量和afterBlur编辑器失去焦点(blur)时执行的回调函数。

上面一套完美解决了KindEditor异步加载内容和提交内容到后端的问题。