Rumah > pembangunan bahagian belakang > tutorial php > 简单的ajax分页疑问,该如何处理

简单的ajax分页疑问,该如何处理

WBOY
Lepaskan: 2016-06-13 10:19:27
asal
767 orang telah melayarinya

简单的ajax分页疑问

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><title>ajax分页</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="description" content=""><meta name="keywords" content=""><script type="text/javascript">function ajax() {    var ajax = false;    if(window.XMLHttpRequest) {        ajax = new XMLHttpRequest();    } else {        ajax = new ActiveXObject("Microsoft.XMLHTTP");    }    return ajax;}window.onload = function check(node) {    var parameter = "page=" + node;    var nokia = ajax();    //alert(nokia);return;    nokia.open('POST',"process.php",true);    nokia.setRequestHeader('Content-Type','application/x-www-form-urlencoded');    nokia.send(parameter);    nokia.onreadystatechange = function () {        if(nokia.readyState==4 && nokia.status==200) {            document.getElementById('span1').innerHTML = this.responseText;        }    }}</script><style type="text/css"></style>            <span id="span1"></span>    
Salin selepas log masuk

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $page = isset($_POST['page'])?$_POST['page']+0:1;if($page==0) {$page =1;}$conn = mysql_connect('localhost','root','111111');mysql_select_db('msg');$sql = 'select count(*) from news';$info = mysql_query($sql,$conn);$msg = mysql_fetch_row($info);$counts = $msg[0]; $perpage = 5; $pages = ceil($counts/$perpage); $start = $page - (5-1)/2;$end = $page + (5-1)/2;$start = $start<1?1:$start;$end = ($start+5-1)>$pages?$pages:($start+5-1);$end = $end>$pages?$pages:$end;$start = ($end-5+1)' . $i . ' ';}echo $link;
Salin selepas log masuk


运行上面的html文件 可以显示 1 2 3 4 5 
可一单击超链接时,firefox的debug显示 check is not defined
不是已经innerHTML进来了么,而且奇怪的是那个$page如果不加零的话显示的object element,望朋友解答!!!

------解决方案--------------------

这样呢
function check(node) {
var parameter = "page=" + node;
var nokia = ajax();
//alert(nokia);return;
nokia.open('POST',"process.php",true);
nokia.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
nokia.send(parameter);
nokia.onreadystatechange = function () {
if(nokia.readyState==4 && nokia.status==200) {
document.getElementById('span1').innerHTML = this.responseText;
}
}
}
window.onload = check(node);


------解决方案--------------------
JScript code
window.onload = function (){   check(1);}function check(node) {    var parameter = "page=" + node;    var nokia = ajax();    //alert(nokia);return;    nokia.open('POST',"process.php",true);    nokia.setRequestHeader('Content-Type','application/x-www-form-urlencoded');    nokia.send(parameter);    nokia.onreadystatechange = function () {        if(nokia.readyState==4 && nokia.status==200) {            document.getElementById('span1').innerHTML = this.responseText;        }    }}<br><font color="#e78608">------解决方案--------------------<div class="clear">
                 
              
              
        
            </div></font>
Salin selepas log masuk
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan