JQuery Ajax instances ($. ajax _ $. post _ $. get), jquery. ajax _

Source: Internet
Author: User

JQuery Ajax instances ($. ajax _ $. post _ $. get), jquery. ajax _

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.

 

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

Js Code
1 // 1. $. ajax asynchronous request with json data 2 var aj =$. ajax ({3 url: 'productmanager _ reverseupdat', // 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 serialized asynchronous request with the table content as a string 30 function noTips () {31 var formParam = $ ("# form1 "). serialize (); // serialize the table content as a string of 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. $. asynchronous request for ajax splicing url 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, change the value of validatePassword2 to pwd2Error. This is asynchronous, the return time 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. $. asynchronous request for ajax splicing data 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 $ ("#" nvidivs0000.html (data); 75} 76 });

 

Related Article

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.