|
1.用ajax post數(shù)據(jù)到后臺(tái)頁(yè)面后,接著要重新連接數(shù)據(jù)庫(kù),別以為用之前的session連接過(guò)就可以了
2.為了處理返回亂碼的問(wèn)題,我添加了header("Content-Type:text/html;charset=GB2312");就可以正常顯示了,后來(lái)在firefox下檢驗(yàn),卻提示我下載這個(gè)網(wǎng)頁(yè),上網(wǎng)搜了不少資料,得到一個(gè)模糊的認(rèn)識(shí)就是網(wǎng)頁(yè)代碼有語(yǔ)法錯(cuò)誤,firefox為了安全起見(jiàn)不會(huì)直接顯示而是提示下載,我重新檢查了剛才那條語(yǔ)句,發(fā)現(xiàn)自己多寫(xiě)了個(gè)“/”,把它去掉后問(wèn)題就解決了,哈哈,所以遇到這樣的問(wèn)題,好好檢查一下html tag吧,畢竟firefox可不像ie那樣smart
3.最后說(shuō)一句,做web site的開(kāi)發(fā)者,要負(fù)責(zé)任,別以為在ie下測(cè)試通過(guò)就萬(wàn)事大吉,畢竟不是所有人都用ie,還得要在別的瀏覽器下多做測(cè)試,這樣才顯示出你的專業(yè)水準(zhǔn)
ajax腳本:
復(fù)制代碼 代碼如下:
<script>
function viewpage(p){
if(window.XMLHttpRequest){
var xmlReq = new XMLHttpRequest();
} else if(window.ActiveXObject) {
var xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
}
var formData = "page="+p;
xmlReq.onreadystatechange = function(){
if(xmlReq.readyState == 4){
document.getElementById('content2').innerHTML = xmlReq.responseText;
}
}
xmlReq.open("post", "hotel_list.php", true);
xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlReq.send(formData);
return false;
}
</script>
調(diào)用:
復(fù)制代碼 代碼如下:
header("Content-Type:text/html;charset=GB2312");
$pagesize=10;
//echo $_POST['page'];
$result = mysql_query("Select count(DISTINCT hotelname) FROM ".TBL_HOTELS);
$myrow = mysql_fetch_array($result);
$numrows=$myrow[0];
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
if (isset($_POST['page'])){
$page=intval($_POST['page']);
}
else{
//設(shè)置為第一頁(yè)
$page=1;
}
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
//計(jì)算記錄偏移量
$offset=$pagesize*($page - 1);
//讀取指定記錄數(shù)
$result=mysql_query("select `hotelname` , count( * ) from ".TBL_HOTELS." GROUP BY `hotelname` order by id desc limit $offset,$pagesize");
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
$hotelname[] = $row[0];
$countpeople[] = $row[1];
}
for($a=0;$a<$num;$a++)
{
//$result=mysql_query("select count(title) from " . TBL_Comments ." where `title`=/"".$title[$a]."/"");
//$row = mysql_fetch_row($result);
echo "<TABLE style=/"MARGIN-BOTTOM: 20px/" cellSpacing=0 cellPadding=0 width=100% border=0>/n";
echo "<TBODY>/n";
echo "<TR>/n";
echo "<TD style=/"PADDING-TOP: 5px/" vAlign=top align=left width=80>/n";
//rating_bar($title[$a],5);
echo "</TD>/n";
echo "<TD style=/"PADDING-TOP: 5px/" align=left width=100%><A title=$hotelname[$a] style=/"FONT-SIZE: 14px/" href=#>$hotelname[$a]</A>/n";
echo "</TD></TR>/n";
echo " <TR>/n";
echo "<TD></TD>/n";
echo "<TD style=/"PADDING-LEFT: 0px/">/n";
echo "<IMG src=/"images/comment.gif/" border=0> 推薦人數(shù):($countpeople[$a]) |/n";
echo "<SPAN>平均分:<STRONG></STRONG> (".$count."票) | 評(píng)論數(shù):()</SPAN>/n";
echo "</TD></TR></TBODY></TABLE>/n";
}
echo "<TABLE style=/"MARGIN-TOP: 30px/" cellSpacing=0 cellPadding=0 width=/"100%/"";
echo "border=0>";
echo "<TBODY><TR><TD colSpan=3 height=20>";
echo "<DIV align=center>";
echo "<P align=left><FONT color=red>第".$page."頁(yè)/總".$pages."頁(yè) | 總".$numrows."條</FONT> | ";
if ($page>1) echo "<a onclick=/"viewpage(".$first.")/" href='#'>首頁(yè)</a> | ";
if ($page>1) echo "<a onclick=/"viewpage(".$prev.")/" href='#'>上頁(yè)</a> | ";
if ($page<$pages) echo "<a onclick=/"viewpage(".$next.")/" href='#'>下頁(yè)</a> | ";
if ($page<$pages) echo "<a onclick=/"viewpage(".$last.")/" href='#'>尾頁(yè)</a>";
echo "轉(zhuǎn)到第 <INPUT maxLength=3 size=3 value=1 name=goto_page> 頁(yè) <INPUT hideFocus onclick=/"viewpage(document.all.goto_page.value)/" type=button value=Go name=cmd_goto>";
echo "</P></DIV></TD></TR></TBODY></TABLE>";
php技術(shù):php,ajax實(shí)現(xiàn)分頁(yè),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。