将数据添加到CKEditor jquery

时间:2017-05-26 15:01:29

标签: javascript jquery ajax ckeditor

您好我正在使用此ajax发布并获取数据,之后我想将数据追加回CKEDITOR

请告诉我错误在哪里?

$(".ddlPredefinedTemplate").change(function() {
  var ddlPredefinedTemplate = $("[id*=ddlPredefinedTemplate]");
  var selectedText = ddlPredefinedTemplate.find("option:selected").text();
  var selectedValue = ddlPredefinedTemplate.val();
  $.ajax({
    type: "POST",
    url: "BenchCompanyEmail.aspx/PredefinedTemplate_Select",
    data: '{Value: "' + selectedValue + '" }',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data) {


      CKEDITOR.instances['txtTemplate'].setData(data.d)

    },
    failure: function(response) {
      alert(response);
    }
  });
});

HTML

 <div class="col-xs-12 col-sm-12 col-md-7">
                                        <asp:DropDownList ID="ddlPredefinedTemplate" TabIndex="3" runat="server" CssClass="form-control ddlPredefinedTemplate">
                                        </asp:DropDownList>

                                        <br />
                                    </div>
                                    <div class="col-xs-12 col-sm-12 col-md-5">
                                        <label>
                                            <span style="color: Red">*&nbsp;</span>Template Subject :
                                        </label>
                                    </div>
                                    <div class="col-xs-12 col-sm-12 col-md-7">
                                        <asp:TextBox ID="txtSubject" placeholder="Template Subject" runat="server" TabIndex="4" CssClass="form-control txtSubject"></asp:TextBox>
                                        <br />
                                    </div>
                                    <div class="col-xs-12 col-sm-12 col-md-12 topmg">
                                        <label>
                                            <span style="color: Red">*&nbsp;</span>Template : 
                                        </label>
                                        <CKEditor:CKEditorControl ID="txtTemplate" TabIndex="5" runat="server" Width="100%" Height="200px"
                                            BasePath="../ckeditor"></CKEditor:CKEditorControl>
                                        <br />
                                    </div>

我遇到了这个错误:

  

无法读取属性&#39; setData&#39;未定义的

1 个答案:

答案 0 :(得分:1)

当您使用MasterPage更改时:

CKEDITOR.instances['txtTemplate'];

CKEDITOR.instances['ContentPlaceHolder1_txtTemplate'];

为什么?

由于ASP.NET动态处理控件的ID,因此在客户端,通过JavaScript,您只能访问具有客户端ID的动态生成控件的上下文。

希望这有帮助。