[英]ajax response and html not working properly
Here I am trying to get result in jsp page using ajax but i am getting improper result. 在这里,我试图使用ajax在jsp页面中获得结果,但是却得到了不正确的结果。
Problem: My ajax response is displayed first instead of my table headings. 问题:首先显示我的ajax响应,而不显示表标题。 That means it should show table headings and then table content but not happening.
这意味着它应该显示表标题,然后显示表内容,但不会发生。
my jsp page displaying result 我的jsp页面显示结果
My Ajax code: 我的Ajax代码:
<script>
$(document).ready(function(){
$(function(){
$('#form1').submit(function(e){
e.preventDefault();
var form = $(this);
var post_url = form.attr('action');
var post_data = form.serialize();
$.ajax({
type: 'POST',
url: post_url,
data: post_data,
success: function(msg) {
console.log(msg);
$('#LogsReceived').append(msg);
},
error: function (error) {
console.log(error);
}
});
});
});
});
</script>
Here is my html code: 这是我的html代码:
<div class="result" >
<p>
<table>
<div id="LogsReceived">
<tr>
<th>Index</th>
<th>Type</th>
<th>Severity</th>
<th>Source Host</th>
<th>Source</th>
<th>Program</th>
<th>Priority</th>
<th>Message</th>
<th>User</th>
<th>Facility</th>
<th>Event Time</th>
</tr>
</div>
</table>
</p></div>
Your HTML structure is invalid. 您的HTML结构无效。 You can't have a
div
as a direct child of table
and as a parent of tr
. 您不能将
div
作为table
的直接子级和tr
的父级。 What you're looking for there is thead
or tbody
, not div
. 您要寻找的是
thead
或tbody
,而不是div
。 It's being corrected by the browser, relocating the div
to before the table. 浏览器已对其进行了更正,将
div
重新定位到表的前面 。 (Because it's invalid, the browser can do anything it wants: Put the div
before, put it after, treat it as though it were a tbody
, ...) Putting a table
in a p
is similarly invalid. (由于无效,浏览器可以做任何想做的事情:将
div
放在前面,放在后面,然后当作tbody
对待,...)将table
放在p
中同样无效。 You can see the rearrangement with the dev tools of your browser: Just right-click the table headers and choose "Inspect element" (or similar): 您可以使用浏览器的dev工具查看重新排列:只需右键单击表标题,然后选择“检查元素”(或类似内容):
I recommend reviewing the various rules for what elements can go where in the spec . 我建议您查看哪些元素可以去那里的各种规则规范 。
Probably, you want both thead
and tbody
: 可能,您既需要
thead
tbody
:
<table>
<thead>
<tr>
<th>Index</th>
<th>Type</th>
<th>Severity</th>
<th>Source Host</th>
<th>Source</th>
<th>Program</th>
<th>Priority</th>
<th>Message</th>
<th>User</th>
<th>Facility</th>
<th>Event Time</th>
</tr>
</thead>
<tbody id="LogsReceived">
</tbody>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.