What does jquery asynchronous request mean?

WBOY
Release: 2022-06-24 16:31:37
Original
1576 people have browsed it

jquery asynchronous request means that after the browser sends a request to the server, it can send the next request at any time without waiting for the server response to return. That is, the data before the request is sent is not lost, and partial parts of the page can be realized. Refresh; Ajax, "$.get()", "$.post()" and "$.getJSON()" can be used to implement asynchronous requests.

What does jquery asynchronous request mean?

The operating environment of this tutorial: windows10 system, jquery3.6.0 version, Dell G3 computer.

What does jquery asynchronous request mean

Asynchronous request

When the browser sends a synchronous request to the server, during the process of the service processing the synchronous request, The browser will be in a waiting state. After the server processes the request, it responds with data to the browser and overwrites the original data in the browser's memory. The browser reloads the page and displays the server's response data.

So, is there a technology that allows the browser to send a request to the server? While the server is processing the request, the browser is not in a waiting state, and the browser does not reload while receiving the response data. For the entire page, the data before the request is sent is not lost, and the partial refresh of the page can be achieved? Then you need to use ajax request - asynchronous request model

Synchronous request means that after sending a request, you need to wait for the server response to return before sending the next request.

Asynchronous requests are opposite to synchronous requests. Asynchronous requests do not need to wait for a response and can send the next request at any time.

Four ways of jQuery asynchronous requests

The first Ajax request:
Save data to the server and display information when successful

$.ajax({
 type: “POST”,
 url: “some.php”,
 data: “name=John&location=Boston”,
 success: function(msg){
 alert( "Data Saved: " + msg );
 }
 });
Copy after login

Comments:
l type: (default: "GET"), request method ("POST" or "GET") Other request methods are only supported by some browsers.
l url: (default current page address) the address to send the request.
l data: stored data.
l success: Called after the request, the returned data and the string containing the success code are transferred.
l Function() needs to store the global variables declared on the controller side

The second $.get() request:
(via remote HTTP GET request Load information. This is a simple GET request function to replace the complex $.ajax. A callback function can be called when the request is successful. If you need to execute a function on an error, use $.ajax.)
Description:
Display the test.php return value (HTML or XML, depending on the return value).
jQuery code:

$.get(“test.php”, function(data){
 alert("Data Loaded: " + data);
 });
Copy after login

Third $.post() request:
(Load information through remote HTTP POST request)
Description:
Output the results from the requested page test.php (HTML or XML, depending on what is returned):
jQuery code:

$.post(“test.php”, function(data){
 alert("Data Loaded: " + data);
 });
Copy after login

Fourth $.getJSON ()Request:
(Load JSON data via HTTP GET request)
jQuery code:

$.getJSON(“http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format
 =json&jsoncallback=?”, function(data){
 $.each(data.items, function(i,item){
 $("").attr(“src”, item.media.m).appendTo("#images");
 if ( i == 3 ) return false;
 });
 });
Copy after login

Note:

l $.getJSON() The request is different from the first three. What is returned in the controller is not the Content but the code in JSON format
What does jquery asynchronous request mean?

Video tutorial recommendation: jQuery video tutorial

The above is the detailed content of What does jquery asynchronous request mean?. 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!