以MVC为框架和Ajax实现分页的效果
fenyeController.class.php文件 <?php $first_a = "<a onclick='viewpage(".$first.")' href='#'>首页</a>"; //命令视图层显示数据 } ?> goodsModel.class.php文件 <?php <html> <head> <meta charset="utf-8"> <script> function viewpage(page){ var xhr; if(window.ActiveXObject){ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ xhr = new XMLHttpRequest(); } var url = "index.php?c=fenye&a=process"; xhr.open("POST",url,true); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xhr.onreadystatechange = callback; xhr.send("page="+page); function callback(){ if(xhr.readyState==4){ if(xhr.status==200){ //alert(xhr.responseText); var json = eval("("+xhr.responseText+")"); var str = json.str; document.getElementById("para").innerHTML = str; for(var i=0;i<json.info.length;i++){ var info = json.info[i].id+json.info[i].name+json.info[i].author+json.info[i].public+json.info[i].isbn+json.info[i].type+json.info[i].price; document.getElementById('div').innerHTML = info; } //alert(json.str); //alert(json.str); /*for(var i=0;i<json.info.length;i++){ alert(json.info[i].name); } */ } } } } </script> </head> <body onLoad="viewpage(1)"> <h3 align="center">数据分页显示</h3> <table style="margin-bottom:20px;margin:auto;border:1px solid;border-spacing:1"> <tr> <th>ID</th><th>名称</th><th>作者</th><th>出版社</th><th>ISBN号</th><th>类型</th><th>价格</th> </tr> <{foreach from=$list item="value"}> <tr> <td style="padding-top:5px;"><{$value.id}></td> <td style="padding-top:5px;"><{$value.name}></td> <td style="padding-top:5px;"><{$value.author}></td> <td style="padding-top:5px;"><{$value.public}></td> <td style="padding-top:5px;"><{$value.isbn}></td> <td style="padding-top:5px;"><{$value.type}></td> <td style="padding-top:5px;"><{$value.price}></td> </tr> <{/foreach}> </table> <table align="center" style="margin-top:15px"> <tr> <td style="colspan:3;height:20"> <p id="para"></p> </td> </tr> </table> <div id="div"></div> </body> </html> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |