In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what are the methods of jquery asynchronous requests". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
There are four kinds of jquery asynchronous requests: 1, Ajax request, syntax for "$.ajax ({name:value, …})"; 2, get request, syntax for "$.get (url, passed parameters, callback function, type)"; 3, getJSON request, support for cross-domain calls; 4, post request.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
There are several kinds of jquery asynchronous requests
The first Ajax request:
$.ajax (): is the core method.
The $.ajax () method is a powerful and direct way to create Ajax requests. It is passed to it using an option object as an argument, and its properties configure all instructions needed to complete the request.
$.ajax () provides callback functions for success and failure.
Syntax:
$.Ajax ({name:value, name:value, … })
Save the data to the server and display information on success
$.ajax ({type: "POST", url: "some.php", data: "name=John&location=Boston", success: function (msg) {alert ("Data Saved:" + msg);}})
Note:
Type: (default: "GET"), request method ("POST" or "GET") other request methods are only supported by some browsers.
Url: (default current page address) the address from which the request was sent.
Data: stored data.
Success: called after the request and transferred to the returned data and the string containing the success code.
The global variable declared by the controller needs to be stored in Function ().
The second $.get () request:
Syntax:
Get (url address, parameters passed by param, callback function, return value type)
Note:
Parameters: optional
Return value type: the type can be automatically matched according to the data (generally omitted)
Request to load information via remote HTTP GET. This is a simple GET request function to replace the complex $. Ajax. The callback function can be called when the request is successful. If you need to execute the function when something goes wrong, use $.ajax. )
Description:
Displays the test.php return value (HTML or XML, depending on the return value).
JQuery Code:
$.get ("test.php", function (data) {alert ("Data Loaded:" + data);})
The third $.post () request:
Syntax:
$.post (url address, parameters passed by param, callback function, return value type)
Note:
Parameters: optional
Return value type: the type can be automatically matched according to the data (generally omitted)
(request for loading information via remote HTTP POST)
Description:
Output the result from the request page test.php (HTML or XML, depending on what is returned):
JQuery Code:
$.post ("test.php", function (data) {alert ("Data Loaded:" + data);})
The fourth $.getJSON () request:
GetJSON () is set specifically for ajax to get json data and supports cross-domain calls.
Note: JSON is an ideal data transfer format, it can be well integrated with JavaScript or other host languages, and can be used directly by JS.
Syntax:
$.getJSON (url address, parameters passed by param (optional), callback function)
(load JSON data through 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 (iMagin item) {$("
") .attr (" src ", item.media.m) .appendto (" # images "); if (I = = 3) return false;});})
Note:
The $.getJSON () request is different from one point in the previous three. The return in the controller is not Content but code in JSon format.
This is the end of the content of "what are the methods of jquery asynchronous requests". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.