PHP+Ajax Click to Load More List Data Examples

A simple and practical PHP+Ajax Click to load more list data instances, the realization of the principle: through the "more" button to the server side to send Ajax requests, PHP according to paging parameters query the latest records, the data returned in JSON form, foreground Query parse JSON data, and add data to the list page. Actually, it's also the effect of Ajax paging.

html code:

 1 <div id="more">  
 2      <div class="single_item">  
 3            <div class="element_head">  
 4                <div class="date"></div>  
 5                <div class="author"></div>  
 6             </div>  
 7             <div class="content"></div>  
 8      </div>  
 9      <a href="javascript:;" class="get_more">::Click to load more content::</a>  
10 </div>

Introduce jQuery plug-ins and jquery.more.js to load more plug-ins:

1 <script type="text/javascript" src="jquery.js"></script>  
2 <script type="text/javascript" src="jquery.more.js"></script>
3 $(function(){  
4     $('#more').more({'address': 'data.php'})  
5 });

data.php receives two parameters submitted from the front page, $_POST['last'] is the number of records, and $_POST['amount'] is the number of records displayed one time. Looking at the SQL statement, you can see that it is actually the statement used in the paging.

 1 require_once('connect.php'); 
 3 $last = $_POST['last']; 
 4 $amount = $_POST['amount']; 
 6 $query = mysql_query("select * from article order by id desc limit $last,$amount"); 
 7 while ($row = mysql_fetch_array($query)) { 
 8     $sayList[] = array( 
 9         'title' => "<a href='".$row['id'].".html' target='_blank'>".$row['title']."</a>", 
10         'author' => $row['id'], 
11         'date' => date('m-d H:i', $row['addtime']) 
12     ); 
13 } 
14 echo json_encode($sayList);

This paper refers to: Reprinted please indicate the source!

Keywords: PHP JQuery Javascript JSON

Added by AbsolutelyFreeW on Wed, 02 Oct 2019 12:07:07 +0300