Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我不能使用jQuery将HTML动态添加到页面?_Javascript_Jquery_Html_Ajax_Twitter Bootstrap - Fatal编程技术网

Javascript 为什么我不能使用jQuery将HTML动态添加到页面?

Javascript 为什么我不能使用jQuery将HTML动态添加到页面?,javascript,jquery,html,ajax,twitter-bootstrap,Javascript,Jquery,Html,Ajax,Twitter Bootstrap,我看到了引导模式对话框的以下HTML代码: <div class="modal fade" id="rebateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-he

我看到了引导模式对话框的以下HTML代码:

<div class="modal fade" id="rebateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Submit Form</h4>
      </div>
      <div class="modal-body">
        <p style="text-align: justify;"><span style="font-weight: 700;"></p>  
        <br/>
        <!-- Here I want to dynamically add the HTML from AJAX response -->
        <form id="request_form" method="post" class="form-horizontal" action="">
        </form>
      </div>
    </div>
  </div>
</div>
引导模式中没有新的HTML

变量响应包含以下字符串:

Id can't be blank<br>Please select Date<br>Image can't be blank<br>
请在这方面帮助我

htrmlString不是htmlString

选择器div.modal-body:first child将不匹配任何元素,因为div.modal-body不是其容器的第一个子元素。就我所见,您只有一个.modal实体,然后您可能可以删除:first-child伪选择器

试试这个:$htmlString.insertBefore'div.modal-body'

根据你的评论:

如果需要在模式中的表单之前插入内容,请尝试以下操作:

$(htmlString).insertBefore('div.modal-body #request_form');

@海恩:谢谢你指出错误。我纠正了它,错误已经消失了,但仍然没有得到新的HTML。是的,HTML即将出现,但它不在我要求的位置,即在after和中。在这方面你能帮我吗?你能缩短formdata吗?formdata:form.serialize到formdata | | form.serialize。
ReferenceError: htmlString is not defined
Id can't be blank<br>Please select Date<br>Image can't be blank<br>
$(htmlString).insertBefore('div.modal-body #request_form');