Jquery is well encapsulated in asynchronous submission, and it is very troublesome to directly use Ajax. jquery greatly simplifies our operations and does not have to worry about browser surprises.
A good jquery Ajax instance is recommended.ArticleIf you forget it, you can check it out,
Address:Http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html and http://www.w3school.com.cn/jquery/
$. Post and $. Get are some simple methods. To process complicated logic, you still need to use jquery. Ajax ()
I. general format of $. Ajax
$. Ajax ({
Type: 'post ',
URL:URL,
Data:Data,
Success:Success,
Datatype:Datatype
});
2. $. Ajax parameter description
Parameter description
URL |
Required. Specifies the URL to which the request is sent. |
Data |
Optional. Ing or string value. Specifies the data sent to the server together with the request. |
Success (data, textstatus, jqxhr) |
Optional. The callback function executed when the request is successful. |
Datatype |
Optional. Specifies the expected server response data type. Intelligent judgment (XML, JSON, script, or HTML) is performed by default ). |
Iii. Notes for $. Ajax:
1. There are three main methods of data: HTML splicing, JSON array, Form serialized by serialize (); specified by datatype, no smart judgment is specified.
2. $. Ajax only submits the form in text mode. If the asynchronous submission contains <File> upload is not passed, you need to use $. ajaxsubmit of jquery. Form. js.
Iv. Examples of my actual applications of $. Ajax
1 // 1. $. Ajax asynchronous requests with JSON data 2 VaR AJ = $. Ajax ({ 3 URL: 'productmanager _ reverseupdate ', // Jump to action 4 Data :{ 5 Selrollback: selrollback, 6 Seloperatorscode: seloperatorscode, 7 Provincecode: provincecode, 8 Pass2: pass2 9 }, 10 Type: 'post' , 11 Cache: False , 12 Datatype: 'json' , 13 Success: Function (Data ){ 14 If (Data. MSG = "true" ){ 15 // View ("modified successfully! "); 16 Alert ("modified successfully! " ); 17 Window. Location. Reload (); 18 } Else { 19 View (data. msg ); 20 } 21 }, 22 Error: Function (){ 23 // View ("exception! "); 24 Alert ("exception! " ); 25 } 26 }); 27 28 29 // 2. $. Ajax serialize asynchronous requests whose table content is a string 30 Function Notips (){ 31 VaR Formparam = $ ("# form1"). serialize (); // Serialize the table content as a string 32 $. Ajax ({ 33 Type: 'post', 34 URL: 'notice _ notipsnotice' , 35 Data: formparam, 36 Cache: False , 37 Datatype: 'json' , 38 Success: Function (Data ){ 39 } 40 }); 41 } 42 43 44 // 3. $. Ajax concatenate URL asynchronous requests 45 VaR YZ = $. Ajax ({ 46 Type: 'post' , 47 URL: 'validatepwd2 _ checkpwd2? Password2 = '+ Password2, 48 Data :{}, 49 Cache: False , 50 Datatype: 'json' , 51 Success: Function (Data ){ 52 If (Data. MSG = "false ") // If the server returns false, the value of validatepassword2 is changed to pwd2error. This is asynchronous and the return time must be considered. 53 { 54 Textpassword2.html ("<font color = 'red'> incorrect business password! </Font>" ); 55 $ ("# Validatepassword2"). Val ("pwd2error" ); 56 Checkpassword2 = False ; 57 Return ; 58 } 59 }, 60 Error: Function (){} 61 }); 62 63 64 // 4. $. Ajax concatenates data asynchronous requests 65 $. Ajax ({ 66 URL: '<% = request. getcontextpath () %>/KC/kc_checkmernameunique.action' , 67 Type: 'post' , 68 Data: 'mername = '+ Values, 69 Async: False , // The default value is true asynchronous. 70 Error: Function (){ 71 Alert ('error'); 72 }, 73 Success: Function (Data ){ 74 $ ("#" + Divs).html (data ); 75 } 76 });