What is the difference between get and post methods in jquery

青灯夜游
Release: 2022-12-12 17:42:38
Original
2602 people have browsed it

Difference: 1. The data in get is sent in the URL, while the data in POST is sent in the body of the text; 2. Only a limited amount of data can be sent in get, but a large amount can be sent in POST. 3. The data sent by the GET method will be disclosed in the URL column, while the data sent by the POST method is not public and has high security.

What is the difference between get and post methods in jquery

The operating environment of this tutorial: windows7 system, jquery3.6.1 version, Dell G3 computer.

jQuery $.get() method

$.get() method requests data from the server via an HTTP GET request.

Syntax:

$.get(URL,callback);
Copy after login

Required URL parameters specify the URL you wish to request.

The optional callback parameter is the name of the function to be executed after the request is successful.

The following example uses the $.get() method to retrieve data from a file on the server:

Example

$("button").click(function(){
$.get("demo_test.asp",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Copy after login

jQuery $. post() method

#$.post() method requests data from the server via HTTP POST request.

Syntax:

$.post(URL,data,callback);
Copy after login

Required URL parameters specify the URL you wish to request.

The optional data parameter specifies the data to be sent with the request.

The optional callback parameter is the name of the function to be executed after the request is successful.

The following example uses $.post() to send data along with the request:

Example

$("button").click(function(){
$.post("demo_test_post.asp",
{
name:"Donald Duck",
city:"www.gqgzdg.com"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Copy after login

jQuery $.get() method and $ The difference between the .post() method

1. The amount of data sent

In GET, only a limited amount of data can be sent, because The data is sent in the URL.

In POST, a large amount of data can be sent because the data is sent in the body of the text.

2. Security

The data sent by the GET method is not protected because the data is exposed in the URL bar, which increases the risk of vulnerabilities and hacker attacks.

The data sent by the POST method is safe because the data is not exposed in the URL bar and a variety of encoding techniques can be used in it, which makes it resilient.

3. Add to bookmarks

The result of GET query can be added to bookmarks because it exists in the form of URL;

And POST query The results cannot be bookmarked.

4. Encoding

When using the GET method in the form, only ASCII characters are accepted in the data type.

When the form is submitted, the POST method does not bind the form data type and allows binary and ASCII characters.

5. Variable size

The variable size in the GET method is about 2000 characters.

The POST method allows a variable size of up to 8MB.

6. Cache

The data of the GET method can be cached,

The data of the POST method cannot be cached.

7. Main function

The GET method is mainly used to obtain information,

and the POST method is mainly used to update data.

[Recommended learning: jQuery video tutorial, web front-end video]

The above is the detailed content of What is the difference between get and post methods in jquery. 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