In-depth analysis of Ajax (main differences between $. post and $. get)-series (II),. post. get

Source: Internet
Author: User

In-depth analysis of Ajax (main differences between $. post and $. get)-series (II),. post. get

The previous series explained the load method of ajax. Now, the other two methods included in layer 2nd: $. post and $. get.

The first thing to clarify is that the $. get method uses the GET Method for asynchronous requests. $. The post method uses the POST method for asynchronous requests.

$. Get

Its structure is as follows:

$. Get (url [, data] [, callback] [, type])

Url: the URL of the requested HTML page

Data (optional): The key/value data sent to the server is not attached to the request URL as QueryString.

Callback (optional): The callback function (called only when the return status of Response is success) automatically passes the request results and status to this method when the load is successful.

Type (optional): Format of the content returned by the server, including xml, html, script, json, text, and _ default.


Example:

$(function(){$("#send").click($.get("get3.php",{username: $("#username").val()content:$("#content").val()},function(data,textStatus){var username=data.user..................},"json"));});

$. Post

The structure and usage are basically the same as those of get. But there are also some major differences

1) The GET request will pass the parameters following the URL, while the POST request will be sent to the WEB server as the entity content of the HTTP message. Of course, in Ajax requests, this difference is invisible to users.

2) The GET method has a limit on the size of data transmitted. Generally, the size of data transmitted in the POST mode cannot exceed 2 kb, but the size of data transmitted in the POST mode is much larger than that in the GET mode, which is theoretically unrestricted.

3) the data requested by the GET method will be cached by the browser, so others can read the data from the browser's historical records, such as accounts and passwords. In some cases, the GET method may cause serious security problems. The POST method can avoid these problems.

4) The GET and POST methods also obtain different data on the server. In PHP, data in GET mode can be obtained using $ _ GET [], while data in POST mode can be obtained using $ _ POST. You can use $ _ REQUEST [] to obtain both methods.


The above are some of the main differences and functions of $. get $ post.

Friends with each other can pay attention to each other !!!!


What is the difference between jquery $ ajax $ get $ post?

Load remote data using HTTP requests.

JQuery underlying AJAX implementation. For easy-to-use high-level implementation, see $. get, $. post, and so on. $. Ajax () returns the created XMLHttpRequest object. In most cases, you do not need to directly operate on this function unless you need to operate on uncommon options for more flexibility.

In the simplest case, $. ajax () can be directly used without any parameters.

Note that all options can be set globally using the $. ajaxSetup () function.
Check the API ~!

What is the difference between jquery $ ajax $ get $ post?

Both get and post use Asynchronous interaction, but if you want to use post and get for Synchronous calls, it won't work $. ajax supports both asynchronous and synchronous use, and both get and post

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.