jQuery不会在HTML文档中输入一些信息

时间:2019-04-08 11:23:43

标签: php jquery html ajax

我正在编写的在线预订Web应用程序中有一个搜索功能,该功能是通过AJAX请求完成的,当执行搜索请求时,php doc /服务器的确会提供正确的信息:

<tr class='hover'>
    <td class='files fileName'/> result1 </td> 
    <td class='owner files name green' >Available</td> 
</tr>
<tr class='hover'> 
    <td class='files fileName'/> result2 </td> 
    <td class='owner files name green' >Available</td> 
</tr>
<tr class='hover'> 
    <td class='files fileName'/> result3 </td> 
    <td class='owner files name green' >Available</td> 
</tr>

但是,如果我检查元素,我会得到:

<tr class='hover'>
    <td class='files fileName'/></td> 
    <td class='owner files name green' >Available</td> 
</tr>
<tr class='hover'> 
    <td class='files fileName'/></td> 
    <td class='owner files name green' >Available</td> 
</tr>
<tr class='hover'> 
    <td class='files fileName'/></td> 
    <td class='owner files name green' >Available</td> 
</tr>

请注意,在第二个示例中,每个<tr>的第二行在<td>

中都没有结果

我的jquery代码如下:

$("#table").empty(); //to empty the rable of default results
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200){
        $("#table").html(xhttp.responseText); //should put the new data into the table
        console.log(xhttp.responseText);
    }
}

jquery为什么只忽略那些值?似乎精确地是随机的,但是它在字符串的中间,所以没有任何意义。

1 个答案:

答案 0 :(得分:0)

我现在解决了这个问题,这就是我的解决方法。

TL; DR,我很笨

我不小心在/的末尾添加了结尾处的<td>,以至于它变成了td class='files fileName'/>,从而导致了并发症。

感谢用户Ivar向我指出这一点

相关问题