Http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html
Usage of $.get, $.post, $.getjson and $.ajax in jquery
1, $.get
The $.get () method uses the Get method to make an asynchronous request with the syntax structure:
$.get (URL [, data] [, callback])
Explain each parameter of this function:
Url:string type, the address of the AJAX request.
Data: Optional parameter, object type, Key/value data sent to the server is appended to the request URL as querystring.
Callback: Optional parameter, function type, which is called automatically when Ajax returns successfully.
Finally write an example of $.get () for your reference:
| 1234567891011 |
$.get( "submit.aspx",{ id: ‘123‘, name: ‘青藤园‘, },function(data,state){ //这里显示从服务器返回的数据 alert(data); //这里显示返回的状态 alert(state); }) |
2, $.post ()
The $.post () method uses the Post method to make an asynchronous request with the syntax structure:
$.post (Url,[data],[callback],[type])
This method is similar to $.get (), except that there is one more type parameter, so here is only the type parameter bar, other references above $.get ().
Type:type is the requested data type, can be a type of Html,xml,json, if we set this parameter to: JSON, then the returned format is in JSON format, if not set, and $.get () return the same format, is a string.
Finally write an example of $.post () for your reference:
| 123456789101112 |
$.post( "submit.aspx",{ id: ‘123‘, name: ‘青藤园‘, },function(data,state){ //这里显示从服务器返回的数据 alert(data); //这里显示返回的状态 alert(state); }, "json") |
3, $.getjson ()
$.getjson () is set up to get JSON data specifically for Ajax, and supports cross-domain calls in the following syntax:
Getjson (Url,[data],[callback])
Url:string type, send request address
Data: Optional parameter, to be sent Key/value parameter, same as Get,post type of data
Callback: Optional parameter, callback function for load success, same as Get,post type callback
JSON is an ideal data transmission format, it can be well fused with JavaScript or other host language, and can be used directly by JS. Using JSON to send "naked" data directly through GET, post, is structurally more reasonable and more secure. As for jquery's Getjson () function, it's just a simplified version of the Ajax () function that sets the JSON parameter. This function can also be used across domains, with a certain advantage over get () and post (). In addition, this function can be used to write the request URL as a "myurl?callback=x" format, so that the program executes the callback function X.
4, $.ajax ()
$.ajax () is a common Ajax package in jquery, with the syntax in the following format:
$.ajax (Options)
Where options is an object type, it indicates the specific parameters of this Ajax call, and here I enclose some of the most commonly used parameters
| 1234567891011121314 |
$.ajax({ url: ‘submit.aspx‘, datatype: "json", type: ‘post‘, success: function(e) { //成功后回调 alert(e); }, error: function(e){ //失败后回调 alert(e); }, beforeSend: function(){ /发送请求前调用,可以放一些"正在加载"之类额话 alert("正在加载"); }}) |
Basic usage of ASP. NET MVC Webapi