Javascript 使用模式更新textarea时Jquery.html()函数出现问题

Javascript 使用模式更新textarea时Jquery.html()函数出现问题,javascript,html,jquery,Javascript,Html,Jquery,我试图创建一个模式,允许用户编辑相应数据库上的备注字段 问题是,在我提交一些表单数据之前,它一直工作,之后textarea不会用新数据更新,它只显示提交的数据 要记住一些事情: 备注字段以纯文本形式存储在后端数据库中。 “AjaxGetData.wc”(参见下面的代码)以HTML格式返回字段内容。 我正在使用一个名为jquery.form.js的javascript类在模式中提交表单数据 因此,我有一个包含表单的模式,表单上有一个textarea,这个textarea的名称会根据在数据表中单击的

我试图创建一个模式,允许用户编辑相应数据库上的备注字段

问题是,在我提交一些表单数据之前,它一直工作,之后textarea不会用新数据更新,它只显示提交的数据

要记住一些事情: 备注字段以纯文本形式存储在后端数据库中。 “AjaxGetData.wc”(参见下面的代码)以HTML格式返回字段内容。 我正在使用一个名为jquery.form.js的javascript类在模式中提交表单数据

因此,我有一个包含表单的模式,表单上有一个textarea,这个textarea的名称会根据在数据表中单击的元素动态更改

然后,单击href打开模式时,将运行一个ajax请求,该请求收集所请求元素的数据(带有HTML格式),并使用$('#myTextArea').HTML(字符串)将其插入textarea

这一切都是可行的,但在提交一些更改的文本后,所有后续的模态请求都会加载第一个提交的字符串,无论我在数据表中单击哪一行。尽管在console.log中,它显示了ajax post返回的正确字符串

理想情况下,我希望理解为什么在我提交了一些数据之后.html()函数停止工作

请参阅下面我的代码:

\\HTML
<!-- START -->
<div class="modal fade" id="editLogoPnotModal" tabindex="-1" role="dialog" aria-labelledby="editLogoPnotLabel"
  aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
    <div class="modal-content">
    <form id="editLogoPnot-Form" action="AjaxTableFieldUpdate.wc" method="post">
      <!--Header-->
      <div class="modal-header alert-primary">
        <h4 class="modal-title" id="myModalLabel">Artwork Production Notes</h4>
        <button type="button" id="editLogoPnot-closebtn" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times</span>
        </button>
      </div>
      <!--Body-->
      <div class="modal-body">
        <div class="md-form">
          <i class="fas fa-pencil-alt prefix"></i>
          <textarea id="editLogoPnot" name="ThisChangesDynamically" class="md-textarea form-control" rows="10" style="white-space: pre-wrap; overflow-y: scroll;"></textarea>
        </div>
      </div>
      <!--Footer-->
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Save</button>
      </div>
    </form>
    </div>
  </div>
</div>
<!-- END -->

\\SCRIPTS
  $('#dtSjob').on('click', 'a.editLogoPnot', function (e) {
    e.preventDefault();

   // Get the data of the selected row from the data table
    epData = sjobTable.row( $(this).closest('tr')).data()

   // Change the name attr of the textarea to identify the requested data
    console.log($("#editLogoPnot").attr('name'))
    $("#editLogoPnot").attr('name', 'logosxzxurnxzx'+epData['sjob']['logourn']+'xzxpnotxzxM');
    console.log($("#editLogoPnot").attr('name'))

   // Get the latest notes for LogoURN
    $.ajax({ url: "AjaxGetData.wc?ti=Logos;urn&fl=pnot&key=urn:C:"+epData['sjob']['logourn'],
       type: "POST",
       success: function(data) {
             // The below line ALWAYS displays the correct data
             console.log("Returned data: "+data);

             // The below line only works before I submitted some changed data, then it stops working.
             $("#editLogoPnot").html(data);
       }
    });
  });

\\ The below function handles the submit of the modal form
  var editLogoPnotoptions = {
      success:       editLogoPnot_showResponse
  };

  $('#editLogoPnot-Form').submit(function() {
      $(this).ajaxSubmit(editLogoPnotoptions);
      // !!! Important !!!
      // always return false to prevent standard browser submit and page navigation
      return false;
  });

  function editLogoPnot_showResponse(responseText, statusText, xhr, $form)  {
    $('#editLogoPnotModal').modal('hide');
  }

\\HTML
艺术品制作说明
&时代
拯救
\\剧本
$('#dtSjob')。在('click','a.editLogoPnot',函数(e){
e、 预防默认值();
//从数据表中获取所选行的数据
epData=sjobstable.row($(this).closest('tr')).data()
//更改textarea的名称attr以标识请求的数据
console.log($(“#editLogoPnot”).attr('name'))
$(“#editLogoPnot”).attr('name','logosxxxurnxzx'+epData['sjob']['logourn']+'xzxpnotxzxM');
console.log($(“#editLogoPnot”).attr('name'))
//获取LogoURN的最新注释
$.ajax({url:“AjaxGetData.wc?ti=Logos;urn&fl=pnot&key=urn:C:”+epData['sjob']['logourn'],
类型:“POST”,
成功:功能(数据){
//下一行始终显示正确的数据
console.log(“返回数据:+数据”);
//下面的行仅在我提交一些更改的数据之前有效,然后它停止工作。
$(“#editLogoPnot”).html(数据);
}
});
});
\\下面的函数处理模式表单的提交
var editLogoPnotoptions={
成功:editLogoPnot_showResponse
};
$('#editLogoPnot表单')。提交(函数(){
$(this).ajaxSubmit(editLogoPnotoptions);
//!!!重要!!!
//始终返回false以防止标准浏览器提交和页面导航
返回false;
});
函数editLogoPnot_showResponse(响应文本、状态文本、xhr$form){
$('editLogoPnotModal').modal('hide');
}
我已经尝试使用.val()解决了这个问题,但是,我无法在textarea中正确显示数据(它包括所有HTML格式)。如果有人对如何解决这个问题有任何建议,那么这也会解决我的问题

任何建议都将不胜感激,因为我已经用尽了所有的想法


谢谢,Chris,如果我正确理解了这个问题,您可以将响应字符串作为html放入一个临时元素中,并从该元素中以文本形式检索它以放入textarea

const str='**E5654**添加平领标签

测试123’;
常量$div=$('').html(str)
$('textarea').val($div.text())

如果我正确理解了这个问题,您可以将响应字符串作为html放到一个临时元素中,并将其作为文本从该元素中检索出来,放入textarea

const str='**E5654**添加平领标签

测试123’;
常量$div=$('').html(str)
$('textarea').val($div.text())


从服务器返回的“html格式”是什么样子的?从html中提取文本相当容易response@charlietfl对于快速响应:))返回的HTML如下所示:*E5654**添加平领标签 Test123从服务器返回的“html格式”是什么样子的?从html中提取文本相当容易response@charlietfl对于快速响应:))返回的HTML如下所示:*E5654**添加平领标签 太棒了!!!那就行了,非常感谢我已经为此奋斗了两天:)太棒了!!!行得通,非常感谢我已经为此挣扎了两天:))