【发布时间】:2012-10-18 17:45:56
【问题描述】:
我一直是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;
?>
【问题讨论】:
-
“不起作用”是什么意思?它不是用正确的参数调用 php 页面吗? php页面是否以某种方式失败?它是否返回不正确的结果?返回后客户端是否出现故障?与 Firebug 一起花费 5 分钟可以在比您输入问题的时间更短的时间内回答所有这些问题。
-
嗨,保罗,不工作是指排序表不排序。 (有返回有效数据)排序功能通常通过单击标题行单元格来进行asc / desc排序,但在这种方式调用时不会。
-
谢谢保罗.. 我理解链接,但通常希望答案的质量与问题的质量有关。如果是大便,我道歉。
-
导致排序发生的代码在哪里?到目前为止,您发布的所有内容似乎都基于您的 cmets。
标签: javascript php jquery ajax sorttable.js