PHP asynchronous data loading process sharing

黄舟
Release: 2023-03-14 15:42:02
Original
2572 people have browsed it

We use many, many non-refresh functions. Now I will introduce you to an example, which is to implement php+ajax to realize scrolling and loading data without refreshing. The example is very simple. You only need to follow the process. Oh.

1. First, we need to get the height of the browser’s visible area page

PHP asynchronous data loading process sharing

2. Then, what needs to be done when scrolling the page is: calculate the total height of the page (when scrolling to the bottom, the page loads new data, so the total height of the page changes dynamically), calculate the scroll bar position (the scroll bar position also changes with loading) The height of the page changes dynamically), and then construct a formula to calculate the relative proportion

PHP asynchronous data loading process sharing

3. When the scroll bar approaches the page At the end, ajax loading is triggered. In this example, we use jQuery's getJSON method to send a request to the server result.php. The request parameter is page, that is, the number of pages

PHP asynchronous data loading process sharing

4. If the request response successfully returns JSON data, parse the JSON data and append the data to the page DIV#container. If no JSON data is returned, all data is displayed. Complete

PHP asynchronous data loading process sharing

5. The complete jQuery code is as follows

PHP asynchronous data loading process sharing


##6.result.php

When scrolling to the bottom of the page , the front-end Ajax request is sent to result.php. The background program will query the corresponding records in the data table according to the requested data page: page, and output the record set in json format and return it to the front-end for processing

PHP asynchronous data loading process sharing

7. Okay, this ends the introduction of this article, go and see the effect.

Explanation

Generally, asynchronous loading will use the AJAX calling method

The above is the detailed content of PHP asynchronous data loading process sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!