Get and post differences in Ajax

Source: Internet
Author: User

Reference Address: http://blog.csdn.net/laijieyao/article/details/40426257

The first thing to be clear $.get method is to use Get method to make asynchronous request. The $.post method uses post to make an asynchronous request.

$.get

Its structure is:

$.get (URL [, data] [, callback] [, type])

URL: URL address of the requested HTML page

Data (optional): Key/value data sent to the server is not appended to the request URL for querystring

Callback (optional): The callback function when loading succeeds (that is, when the return state of response is called success) automatically passes the request result and state to the method

Type (optional): The format of the server-side return content, including Xml,html,script,json,text and _default.


Examples are as follows:

[JavaScript]View PlainCopy
  1. $ (function () {
  2. $ ("#send"). Click (
  3. $.get ("get3.php", {
  4. Username: $ ("#username"). Val ()
  5. content:$ ("#content"). Val ()
  6. },function (data,textstatus) {
  7. var username=data.user
  8. ..................
  9. },"JSON")
  10. );
  11. });

$.post

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

1) The GET request passes the parameter after the URL, and the POST request is sent to the Web server as the entity content of the HTTP message. Of course, in AJAX requests, this distinction is not visible to the user.

2) The Get method has a limit on the size of the transmitted data, usually not greater than 2KB, and the Post method passes the amount of data is much larger than the Get method, theoretically unrestricted.

3) The data requested by the Get method is cached by the browser, so that other people can read the data from the browser's history, such as account number and password. In some cases, the Get method poses a serious security problem. And the Post method avoids these problems relatively.

4) The Get mode and the post method of the data passed on the server side of the acquisition is not the same. In PHP, the get data can be obtained using $_get[], while POST can be obtained using $_post[]. Both ways can be obtained using $_request[].

Get and post differences in Ajax

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.