How to implement asynchronous loading in PHP

藏色散人
Release: 2023-03-06 17:34:01
Original
3206 people have browsed it

PHP method to implement asynchronous loading: first obtain the height of the browser's visible area page; then construct a formula to calculate the relative proportion; then use jQuery's getJSON method to send a request to the server result.php; finally Just parse the JSON data.

How to implement asynchronous loading in PHP

Recommended: "PHP Video Tutorial"

php asynchronous loading of data

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 just need to follow the process.

Method

First, we need to get the height of the browser's visible area page

How to implement asynchronous loading in PHP

Then, when scrolling the page, we need to do The thing 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 dynamically with the height of the loaded page), and then Construct a formula to calculate the relative proportion

How to implement asynchronous loading in PHP

When the scroll bar is close to the bottom of the page, ajax loading is triggered. In this example, we use jQuery's getJSON method to send the result to the server. PHP sends a request, and the parameter of the request is page, that is, the page number

How to implement asynchronous loading in PHP

#If the request response successfully returns JSON data, parse the JSON data and append the data to the page DIV#container Afterwards, if no JSON data is returned, it means that all the data has been displayed.

How to implement asynchronous loading in PHP

The complete jQuery code is as follows

How to implement asynchronous loading in PHP

result .php

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

How to implement asynchronous loading in PHP

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

The above is the entire content of this article, I hope you all like it

The above is the detailed content of How to implement asynchronous loading in PHP. 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