There are many types of ajax implementation methods in jquery, such as: load, jQuery.get, jQuery.post, jQuery.getScript, jQuery Ajax events, jQuery.ajaxSetup, etc.
First, the general format of $ .ajax
$ .ajax ({
type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType
});
Second, $ .ajax parameter description
Parameter Description
url is required. Specifies which URL to send the request to.
data Optional. Map or string value. Specifies the data to be sent to the server along with the request.
success (data, textStatus, jqXHR) Optional. Callback function executed when the request is successful.
dataType
Optional. Specifies the data type of the expected server response.
Perform smart judgment (xml, json, script or html) by default.
Three, $ .ajax need to pay attention to some places:
There are three main ways of 1.data, html splicing, json array, serial form (serialize ()); specified by dataType, intelligent judgment is not specified.
2. $. Ajax only submits the form in text mode. If the asynchronous submission contains <file> uploading, it will not pass, you need to use $ .ajaxSubmit of jquery.form.js
Fourth, the Ajax case
//1.$.ajax asynchronous request with json data
var aj = $ .ajax ({url: 'productManager_reverseUpdate', // jump to action data: {selRollBack: selRollBack, selOperatorsCode: selOperatorsCode, PROVINCECODE: PROVINCECODE, pass2: pass2}, type: 'post', cache: false, dataType: 'json', success: function (data) {if (data.msg == "true") {// view ("Successfully modified!"); alert ("Successfully modified!"); window.location.reload ();} else {view (data.msg);}}, error: function () {// view ("Exception!"); alert ("Exception!");}}); //2.$. asynchronous request for ajax serialized form content as a string function noTips () {var formParam = $ ("# form1"). serialize (); // serialized form content is a string , url: 'Notice_noTipsNotice', data: formParam, cache: false, dataType: 'json', success: function (data) {}});} //3.$.ajax asynchronous request for splicing var yz = $. ajax ({type: 'post ', url:' validatePwd2_checkPwd2? password2 = '+ password2, data: {}, cache: false, dataType:' json ', success: function (data) {if (data.msg == "false") // The server returns False, change the value of validatePassword2 to pwd2Error, which is asynchronous, you need to consider the return time {textPassword2.html ("<font color = 'red'> The business password is incorrect! </ font> "); $ (" # validatePassword2 "). val (" pwd2Error "); checkPassword2 = false; return;}}, error: function () {}}); //4.$.ajax stitching data $ .Ajax ({url: '<% = request.getContextPath ()%> / kc / kc_checkMerNameUnique.action', type: 'post', data: 'merName =' + values, async: false, // Default is true asynchronous error: function () {alert ('error');}, success: function (data) {$ ("#" + divs) .html (data);}});