将Ajax添加到我的PHP分页
我有一个分页系统,我想在不重新加载整个页面的情况下更改页码,以提高网站速度 这只是我的分页代码(没有ajax)将Ajax添加到我的PHP分页,php,jquery,ajax,pdo,pagination,Php,Jquery,Ajax,Pdo,Pagination,我有一个分页系统,我想在不重新加载整个页面的情况下更改页码,以提高网站速度 这只是我的分页代码(没有ajax) 我尝试向其中添加ajax:这是我的代码,但它不起作用 <head> <script> function showUser(str) { if (str=="") { document.getElementById("pagination").innerHTML=""; return; } if (window.XMLHttpRe
我尝试向其中添加ajax:这是我的代码,但它不起作用
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("pagination").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("pagination").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","a.php?page="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
$stmt = $conn->prepare("SELECT name FROM info LIMIT $limit OFFSET $start");
// Then fire it up
$stmt->execute();
// Pick up the result as an array
$result = $stmt->fetchAll();
// Now you run through this array in many ways, for example
for($x=0, $n=count($result); $x < $n; $x++){
echo "
<div onchange='showUser(this.value)'>
<p id=pagination>" .$result[$x]['movie_name']. "</p>
</div>
";
}
//pagination
echo '<div onchange="showUser(this.value)">';
while ($pagenumber != $totalpages)
{
++$pagenumber;
echo "<a href='?page=".$pagenumber."' >".$pagenumber."</a>";
}
?>
</div>
</body>
函数showUser(str){
如果(str==“”){
document.getElementById(“分页”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“分页”).innerHTML=this.responseText;
}
}
open(“GET”,“a.php?page=“+str,true”);
xmlhttp.send();
}
$stmt=$conn->prepare(“从信息限制中选择名称$LIMIT OFFSET$start”);
//然后点燃它
$stmt->execute();
//将结果提取为数组
$result=$stmt->fetchAll();
//现在,您可以通过多种方式运行此阵列,例如
对于($x=0,$n=count($result);$x<$n;$x++){
回声“
“$result[$x]['movie\u name']”
";
}
//分页
回声';
而($pagenumber!=$totalpages)
{
++$pagenumber;
回声“;
}
?>
什么是错误或bug,或者您想要什么?逻辑bug,它不工作。
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("pagination").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("pagination").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","a.php?page="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
$stmt = $conn->prepare("SELECT name FROM info LIMIT $limit OFFSET $start");
// Then fire it up
$stmt->execute();
// Pick up the result as an array
$result = $stmt->fetchAll();
// Now you run through this array in many ways, for example
for($x=0, $n=count($result); $x < $n; $x++){
echo "
<div onchange='showUser(this.value)'>
<p id=pagination>" .$result[$x]['movie_name']. "</p>
</div>
";
}
//pagination
echo '<div onchange="showUser(this.value)">';
while ($pagenumber != $totalpages)
{
++$pagenumber;
echo "<a href='?page=".$pagenumber."' >".$pagenumber."</a>";
}
?>
</div>
</body>