我不确定哪个部分没有导致页面响应。这些页面是我的 lubuntu 机器中的主机。但是,当我从另一台 LAN 计算机访问此页面时,选择 startDate 为“2012-12-16”,endDate 为“2013-12-16”,页面在 Chrome 浏览器中冻结。知道什么时候结冰吗?当我打电话$.get('duty.php'...
时,警报甚至无法弹出。当我直奔
/attendence/duty.php?mode=9&startDate=2012-12-06&endDate=2013-12-06&christened=All
回报是
[]
*编辑 2 *
找到了原因,结果证明这是另一个“愚蠢”的问题。问题是由$.get()
. 如您所见,php 的输出是一个空数组[]
,这没关系。然而,该$.get()
函数并未将其视为有效响应,只是等到浏览器超时。(使用 jQuery 1.7.2)解决方法是返回带有一些内容的 json,例如{'no','result'}
.
Apache2 访问日志
192.168.1.7 - - [06/Dec/2012:21:02:48 +0800] “GET /attendence/duty.php?mode=9&startDate=2012-12-06&endDate=2013-12-06&christened=All HTTP/1.1” 500 411 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/535.19"
$.get('duty.php',
{'mode':9,
'startDate':$('input[name=startDate]').val(),
'endDate':$('input[name=endDate]').val(),
'christened':$('input[name=christened]:checked').val()},
function(data, textStatus, jqXHR){
alert('result reach back');
if (typeof data === 'undefined') {
return;
}
numWeek = getDiffWeek();
tableHtml='Num Of week:'+numWeek+'<table border=1><tr>';
tableHtml+='<td>Barcode</td><td>name</td><td>attendence</td><td>frequency</td>';
tableHtml+=' </tr></table>';
$('#attendenceRate').html(tableHtml);
for(name in data){
attendenceRate = Math.round(data[name]['times']/numWeek*100);
memberIcon ='';
$('#attendenceRate table').append('<tr><td>'+data[name]['barcode']+'</td><td>'+name+'</td><td>'+attendenceRate+'%</td><td>'+data[name]['times']+'</td></tr>');
}
}
,'json'
);
编辑只是一个错字,应该是duty.php而不是 Duty.php
include ("lock.php");
if($_GET){
if ($_GET['mode']==9){//calculate overall christian attendence
$startDate = $_GET['startDate'];
$endDate = $_GET['endDate'];
$christened=$_GET['christened'];
if($christened=='All'){
$christenedClause='';
}else{
$christenedClause= ' AND record.christened = '.$christened;
}
$sql = <<<EOD
SELECT name,barcode, COUNT( * ) AS times ,christened,gender
FROM (
SELECT name,attendence.barcode as barcode, DATE, TIME,christened,gender
FROM attendence, record
WHERE attendence.barcode = record.barcode
AND DATE
BETWEEN "$startDate"
AND "$endDate"
$christenedClause
GROUP BY name, DATE
)A
GROUP BY name
排爆;
$result = $link->query($sql);
$data = array();
$i=0;
if($result->num_rows>0){
while ($result2 = $result->fetch_assoc()){
$data[$result2['name']]['times'] = $result2['times'];
$data[$result2['name']]['barcode'] = $result2['barcode'];
$data[$result2['name']]['gender'] = $result2['gender'];
$data[$result2['name']]['christened'] = $result2['christened'];
$i++;
}
}
echo json_encode($data);
}
}