Php 通过AJAX接收的表上的jQuery表分类器

Php 通过AJAX接收的表上的jQuery表分类器,php,jquery,ajax,tablesorter,Php,Jquery,Ajax,Tablesorter,我正在写一个脚本,将允许我搜索种子网站。在页面加载时,左侧有一个要搜索的文本区域,右侧有一个空div。搜索使用AJAX提取搜索结果表并附加到右侧的空/非空div。我想使用jQuery插件tablesorter对上述表进行排序。在后端,我逐行循环搜索帖子,形成表格,然后输出。下面是循环的内部: $tables .= "<div align='right' style='border:solid 2px grey'> <div class='subheader'> $

我正在写一个脚本,将允许我搜索种子网站。在页面加载时,左侧有一个要搜索的文本区域,右侧有一个空div。搜索使用AJAX提取搜索结果表并附加到右侧的空/非空div。我想使用jQuery插件tablesorter对上述表进行排序。在后端,我逐行循环搜索帖子,形成表格,然后输出。下面是循环的内部:

$tables .= "<div align='right' style='border:solid 2px grey'>
<div class='subheader'>
    $file
    <input type='button' value='F This' onclick='toggleVis(\"$file.div\")'>
</div>
<div id='$file.div'>
    <table RULES=ROWS FRAME=HSIDES border='1' class='tablesorter' id='$file.table'>
        <thead>
            $headStr
        </thead>
        <tbody>
            $bodyStr
        </tbody>
    </table>

    <input type='button' value='F That--^' onclick='toggleVis(\"$file.div\")'>

</div>
</div>
<br>";
$tables.=”
$file
$headStr
$bodyStr

“;
在处理完所有数据后,我只是回显$tables。下面是AJAX调用+jquery初始化:

function doSearch(){
    var http;  
    try{
            // Opera 8.0+, Firefox, Safari
            http = new XMLHttpRequest();
    } catch (e){
            // Internet Exploder
            try{
                    http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                    try{
                            http = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e){
                            // Bad 
                            alert("Your browser derped!");
                            return false;
                    }
            }
    }

    http.onreadystatechange = function(){
        if(http.readyState == 4){
            if(document.getElementById('clearResults').checked)
                document.getElementById('searchResults').innerHTML = http.responseText;
            else
                document.getElementById('searchResults').innerHTML += http.responseText;

            $("table").tablesorter();  //  Initialize tablesorting
        }
    }
    search = encodeURIComponent(document.getElementById('search').value);
    document.getElementById('search').value = '';
    http.open("POST", "<?php echo $_SERVER['PHP_SELF']; ?>", true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    http.send('lAct=search&search='+search);
}
函数doSearch(){
var-http;
试一试{
//Opera 8.0+、Firefox、Safari
http=newXMLHttpRequest();
}捕获(e){
//互联网爆炸器
试一试{
http=新的ActiveXObject(“Msxml2.XMLHTTP”);
}捕获(e){
试一试{
http=新的ActiveXObject(“Microsoft.XMLHTTP”);
}捕获(e){
//坏的
警告(“你的浏览器被破坏了!”);
返回false;
}
}
}
http.onreadystatechange=函数(){
如果(http.readyState==4){
if(document.getElementById('clearResults')。选中)
document.getElementById('searchResults')。innerHTML=http.responseText;
其他的
document.getElementById('searchResults').innerHTML+=http.responseText;
$(“table”).tablesorter();//初始化表排序
}
}
search=encodeURIComponent(document.getElementById('search').value);
document.getElementById('search')。值='';
http.open(“POST”,“true”);
http.setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”)
send('lAct=search&search='+search);
}
因此,上面的代码可以完美地执行,但新表没有排序。有趣的是,初始化tablesorter实际上是将我的类更改为“header”——这意味着它正在工作?对于傻笑,我在页面上添加了一个静态表;在调用搜索函数(以及更改的th类)后,它将变得可排序。有人碰到过这样的事吗?如果需要,我可以发布更多代码;任何帮助都将不胜感激

以防万一,下面是正在输出的最终表格:

<div id="ubuntu.div">
    <table rules="ROWS" frame="HSIDES" border="1" class="tablesorter" id="ubuntu.table">
        <thead>
            <tr><th class="header">Type</th><th class="header headerSortDown">Size</th><th class="header">SE</th><th class="header">LE</th><th class="header">name</th><th class="header">dl</th></tr>
        </thead>
        <tbody>
            <tr class="highlight" id="ubuntu.0"></tr><tr class="highlight" id="ubuntu.0"><td>Video(Other)</td><td><b>267.45MiB</b></td><td>7</td><td>1</td><td>VTC Ubuntu Certification</td><td>

    </td>
</tr><tr class="highlight" id="ubuntu.1"><td>Video(Other)</td><td><b>10.62MiB</b></td><td>1</td><td>1</td><td>Nelson Mandela explains Ubuntu (ideology)</td><td>

    </td>
</tr>
        </tbody>
    </table>

    <input type="button" value="F That--^" onclick="toggleVis(&quot;ubuntu.div&quot;)">

</div>                

TypeSizeLenamedl
视频(其他)267.45MiB71VTC Ubuntu认证
视频(其他)10.62MIB11纳尔逊·曼德拉解释Ubuntu(意识形态)

我还注意到,当我单击表标题时,类正在更改为包含SortDown或SortUp…奇怪的是它没有排序…

有两行具有相同的ID,第一行为空:

<tr class="highlight" id="ubuntu.0"></tr>
<tr class="highlight" id="ubuntu.0">...</tr>

...

为什么有两行具有相同的ID
而第一行完全为空?哇,我觉得自己像个白痴,是重复的ID。非常感谢你!把这个作为答案,这样我就可以接受;)。酷,我很高兴这起作用了!:)