Jquery
$ (function () {//Initialize GetData (0); var index = 1;$ ("#more"). Click (function () {getData (index) index = index + 1;}) var cur_page = 1;var Total, total_page, Page_size;//ajax interactive function getData (pageIndex) {$.ajax ({type: "POST", url: " Test.php ", data: {" PageIndex ": PageIndex},//pass parameters as the background to return page numbers by datatype:" JSON ",//expected data returned as Jsonbeforesend:function () {$ ("#more"). Text ("Loading ...")},success:function (JSON) {////After successfully fetching the data, return the JSON object, which is a JSON name to my understanding is json={... }$ ("#more"). Text ("Load more ..."); total = Json.total; Gets the total attribute value in json pageSize = json.pagesize; Gets the value of the PageSize property in json totalpage = Json.totalpage;var list = json.list; The list in JSON is an array of var li = ""; $.each (list, function (index, content) {//Traversal list array, index is subscript, content is the value of this subscript Li + = "<ul& Gt;<li class= ' question ' > "+ content[' question '] +" </li><li class= ' answer ' > "+ content[' answer '] +" & Lt;/li></ul> ";}); $ ("#list"). Append (LI), if (index >= totalpage) {$ ("#more"). Text ("No"). CSS ("Background", "#555"). Unbind ("click"); Unbind the Click event}},error: function () {alert ("Load Error");}})})
Php
<?phpinclude_once (' conn.php '); $page = Intval ($_post[' pageIndex ');//Receive data from the foreground if (!empty ($page)) {$result = Mysql_ Query ("SELECT ID from Test1"), $total = Mysql_num_rows ($result);//total record number $pagesize = 3; Display number per page $totalpage = ceil ($total/$pageSize); Total pages $startpage = $page * $pageSize; $arr [' totals '] = $total; $arr [' pageSize '] = $pageSize; $arr [' totalpage '] = $totalPage; $ query = mysql_query ("Select Id,question,answer from Test1 ORDER by ID ASC limit $startPage, $pageSize"); while ($row =mysql_f Etch_array ($query)) {//Get all data rows $arr[' list ' [] = array (' id ' = + $row [' ID '],//assigns the value of the ID field in the row to the id ' question ' = = $row [' Question '], ' answer ' = $row [' answer '],);} mysql_query (' SET NAMES UTF8 '), header ("Content-type:text/html;charset = Utf-8"), Echo Json_encode ($arr);//Convert to JSON format, The character format output here is not relevant to the foreground}?>
"jquery, ajax,php" load more instances