我一直是http://www.kryogenix.org/code/browser/sorttable/排序表 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"> </td><td align="right"><b>notes:</b></td><td colspan="4">' . $data['notes_to_picker'].'</td></tr>';
}
$i++;
}
$message.= '</table>';
echo $message;
?>