使用 ajax 更新时无法从 summernote 获取值

Cannot get value from summernote ,when using ajax update

当我点击编辑按钮时(我使用模态 bootstrap)除了 textarea 和 summernote 之外的所有值都存在。

如果你输入了一些东西(在 summernote 中)并取消它,你的值不会消失......应该很清楚。

原谅我,我的英语太烂了。

这是我的模态形式:

    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" ><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title">Formulir Berita</h3>
            </div>
            <div class="modal-body form">
                <form action="#" id="form" class="form-horizontal">
                    <input type="hidden" value="" name="id_berita"/> 
                    <div class="form-body">
                     <div class="form-group">
                            <label class="control-label col-md-2">Tanggal penulisan</label>
                      <div class="col-md-9">
                     <div class="input-group">
                  <span class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                                </span>
     <input name="tgl" placeholder="yyyy-mm-dd" class="form-control datepicker" type="text">
                                    <span class="help-block"></span>
                                </div>

                            </div>
                        </div>
                        <div class="form-group">
   <label class="control-label col-md-2">Judul</label>
                            <div class="col-md-9">
 <input name="judul" placeholder="Judul" class="form-control" type="text">
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
     <label class="control-label col-md-2">Penulis</label>
                            <div class="col-md-9">
 <input name="penulis" placeholder="Penulis" class="form-control" type="text">
                                <span class="help-block"></span>
                            </div>
                        </div>
<div class="form-group" id="photo-preview">
               <label class="control-label col-md-2">Gambar</label>
                            <div class="col-md-4">
                                (Tidak ada gambar)

                            </div>
                        </div>
                        <div class="form-group">
<label class="control-label col-md-2" id="label-photo">Unggah Foto </label>

  <div class="col-md-7">
                                                    <div class="fileupload fileupload-new" data-provides="fileupload">
                                                        <div class="input-append">
                                                            <div class="uneditable-input">
                                                                <i class="fa fa-file fileupload-exists"></i>
                                                                <span class="fileupload-preview"></span>
                                                            </div>
                  <span class="btn btn-default btn-file">                                                                
                  <span class="fileupload-exists">Ganti Foto</span>

                  <span class="fileupload-new">Pilih File</span>
                                                                <input name="gambar" type="file" />
                                                        </span>
             <span class="help-block"></span>
                                                            <a href="#" class="btn btn-default fileupload-exists" data-dismiss="fileupload">Remove</a>
                                                        </div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Isi</label>
 <div class="col-md-9">
<textarea name="isi" class="form-control" id="summernote" >
                            </textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" id="btnSave" onclick="save()" class="btn btn-primary">Simpan</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>

我一直在尝试一些代码:

$('#summernote').summernote('code');
$('#summernote').summernote('reset');// and for resetting modal while Add Data 

什么都没发生

我的ajax函数:

function edit_berita(id)
{
   save_method = 'update';
    $('#form')[0].reset(); // reset form on modals
    $('.form-group').removeClass('has-error'); // clear error class
    $('.help-block').empty(); // clear error string

    //Ajax Load data from ajax
    $.ajax({
        url : "<?php echo site_url('sistem/berita/ajax_edit/')?>/" + id,
        type: "GET",
        dataType: "JSON",
        success: function(data){
            // $('#summernote').summernote('code');
            $('[name="id_berita"]').val(data.id_berita);
            $('[name="tgl"]').datepicker('update',data.tgl);
            $('[name="judul"]').val(data.judul);
            $('[name="isi"]').val(data.isi);
            $('[name="penulis"]').val(data.penulis);

 $('#modal_form').modal('show'); // show bootstrap modal when complete loaded
            $('.modal-title').text('Edit data'); // Set title to Bootstrap modal title

            $('#photo-preview').show(); // show photo preview modal

            if(data.gambar)
            {
                $('#label-photo').text(''); // label photo upload
$('#photo-preview div').html('<img src="'+base_url+'upload/berita/'+data.gambar+'" class="img-responsive" >'); // show photo
                $('#photo-preview div').append('<input type="checkbox" name="remove_photo" value="'+data.gambar+'"/> Remove photo when saving'); // remove photo

            }
            else
            {
                $('#label-photo').text(''); // label photo upload
                $('#photo-preview div').text('(Tidak ada gambar)');
            }         
        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error get data from ajax');
        }
    });
}

Textarea 没有值。 jQuery .html() 在这种情况下有效

$("textarea#summernote").html(data.isi);

请试试这个:

$("textarea#summernote").val(data.isi);

尝试像这样修改 summernote 行:

$('#summernote').summernote('code', data.isi);

并清除内容:

$('#summernote').summernote('code', '');

$( '[name="isi"]' ).val(data.isi);
$( '[name="isi"]' ).summernote();