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
- $ (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 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