javascript - 为什么动态调用(Ajax)时 JavaScript 会失败?

标签 javascript php jquery ajax sorttable.js

我一直是 http://www.kryogenix.org/code/browser/sorttable/ 的 super 粉丝排序表 JavaScript 代码。它在很多层面上都起作用。

也就是说,我最近遇到了一个问题,试图在通过 ajax 调用时使排序工作。我的主页上有一个 div 层,我使用 ajax 调用动态查询来动态填充页面。我想这些结果可以使用上面的 javascript 文件进行排序。然而,事实并非如此,我不明白为什么它不起作用。

我通过在页面上放置相同的查询并在页面正常加载时填充它来验证代码在页面上的工作原理,并且 sorttable.js 工作得非常顺利。

如果有人能告诉我为什么像 javascript 这样的客户端语言在通过 ajax 调用时不起作用,我将不胜感激。我确信这是应该的,但我很可能搞砸了一些事情。

作为引用,这是我的 jquery/ajax

        <script type="text/javascript">
                $(document).ready(function(){
                $(".small_radio").click(function() {

                //check radio buildings for selected value
                var radBuild = $('input:radio[name=buildings]:checked').val();

                //check radio daterange for selected value
                var radDate = $('input:radio[name=daterange]:checked').val();

                //create array for multiple possibilites from checkbox users
                var chkUsers = [];
                //loop through checkboxes appending values to array
                $('#checkall :checked').each(function() {
                   chkUsers.push($(this).val());
                 });

                 //send the request
                $.ajax({
                    url: "/inventory/pick-print-results.php",
                    type: "post",
                    data: "buildings=" + radBuild + "&daterange=" + radDate + "&users[]=" + chkUsers,
                    // callback for success
                     success: function(data, textStatus) {
                         $(".loadonly").hide();
                         $(".ajax_stuff").html(data);  //no data here
                          //alert(data); //Data here
                      }, //end success else...
                      //if failsauce throw error
                      error: function() {
                          alert('Not OKay');
                         } //end error failsauce
                      }); //ends .ajax function
                   }); //end #checkall. click function
                }); // ends ready function
            </script>

这是我通过ajax调用的php查询数据..

<?php $message.='
            <input type="hidden" value="'.$big_chunk_sql.'" id="displayed_sql" name="displayed_sql">
            <input type="hidden" value="'.$row_count.'" id="amount" name="amount">
             <input type="hidden" value="print" id="print" name="print">
            <table border="0" width="100%" class="sortable">
            <th class="admin">Location</th>
            <th class="admin">Pick For</th>
            <th class="admin">Requested Date</th>
            <th class="admin">Part Number</th>
            <th class="admin">Quantity</th>
            <th class="admin">Received Date</th>
            <th class="admin">Action</th>';
            while($data=mysql_fetch_array($big_chunk_query)) {

                //Deal with operator Name Don Ford = D Ford
                list($user_first,$user_last)=explode(' ',$data['description']);
                $user_first=strtoupper(substr($user_first,0,1));
                $user_last=ucfirst($user_last);
                $operator_name=$user_first.' ' . $user_last;

               if ($i%2 !=0)
                 $rowColor = 'tr2center';
                  else
                 $rowColor = 'tr1center';
                    $pendingdate= trim($data['received_date']);
                    $newpendingdate = date('m-d-Y',strtotime($pendingdate));
                    $message.= '<tr class="'.$rowColor.'">
                    <td>'. $data['location'].'</td>
                    <td>'.$operator_name.'</td>
                    <td>'.date("m-j-y, g:i a", strtotime($data['date_requested'])) .'</td>
                    <td>'.$data['part_number'] . '</td>
                    <td>'. $data['qty_requested'] . '</td>
                    <td>'. $newpendingdate . '</td><td> 
                    <a href="picking.php?radiopart='.urlencode($data['org_transaction_id']) .'">Mark Picked</a></td></tr>';
                    if($data['notes_to_picker']!='') { 
                    $message.= '<tr class="'.$rowColor.'" align="center"><td colspan="2">&nbsp;</td><td align="right"><b>notes:</b></td><td colspan="4">' . $data['notes_to_picker'].'</td></tr>';
                    }
                    $i++;
                }
                $message.= '</table>';
                echo $message;
    ?>

最佳答案

如果您阅读您提供的链接上的文档,您的情况就是插件作者认为“高级”的情况。 http://www.kryogenix.org/code/browser/sorttable/#ajaxtables

在成功回调中,您需要 sorttable.makeSortable($("#tableid")[0]);

关于javascript - 为什么动态调用(Ajax)时 JavaScript 会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12960594/

相关文章:

php - 显示连接到登录用户的数据

php - 将 JS 链接到 wordpress

javascript - setInterval 在第一次实例后停止

javascript - 未捕获的类型错误 : undefined is not a function - ember js

javascript - ExpressJS 中的 POST 请求问题

javascript - 如何限制小数的总位数

javascript - 尽管 HTML5 可以完成我需要的一切,为什么我还需要视频播放器引擎?

php - javascript 在 onclick 处包含文件

javascript - 如何获取所有不同的下拉列表是否已选择值

jquery - 通过 Ajax 而不是表单提交从类型 "image"的输入提交数据