jquery is very well encapsulated in asynchronous submissions and is very cumbersome to use Ajax directly, and jquery simplifies our operations without considering the differences in browsers.
$.post, $.get is a simple method, if you want to deal with complex logic, still need to use the Jquery.ajax ()
General format of $.ajax
$.ajax ({
type: ' POST ',
url:url,
data:data,
success:success,
datatype:datatype
});
Ii. Description of $.ajax parameters
Parameter description
URL required. Specify which URL to send the request to.
Data is optional. The mapping or string value. Specify the data to be sent to the server along with the request.
Success (data, Textstatus, JQXHR) is optional. The callback function to execute when the request succeeds.
DataType Optional. Specify the data type of the expected server response.
The default execution of intelligent judgments (XML, JSON, script, or HTML).
third, $.ajax need to pay attention to some places:
1.data main methods are three kinds, HTML splicing, JSON array, form form by serialize () serialization, by datatype specified, do not specify intelligent judgment.
2.$.ajax only submits form in text mode, if the asynchronous commit includes <file> uploads is passed over, need to use Jquery.form.js $.ajaxsubmit
Four, $.ajax my practical application example
1.$.ajax asynchronous request with JSON data var AJ = $.ajax ({url: ' productmanager_reverseupdate ',//Jump to action data:{SELRO Llback:selrollback, Seloperatorscode:seloperatorscode, Provincecode:provincecode, Pass2: PASS2}, type: ' Post ', Cache:false, DataType: ' JSON ', success:function (data) {if (data.msg = = "Tru E ") {//view (" Modified successfully! ")
"); Alert ("Modified successfully!")
");
Window.location.reload ();
}else{view (data.msg); }, Error:function () {//view (Exception!)
"); Alert ("Exception!")
");
}
});
2.$.ajax the asynchronous Request function Notips () {var Formparam = $ ("#form1") for the serialized table contents as a string. Serialize ();//Serialization table contents are string $.ajax ({ Type: ' Post ', url: ' Notice_notipsnotice ', Data:formparam, Cache:false, DataType: ' JSON ', Su
Ccess:function (data) {}}); //3.$.ajax asynchronous request for stitching URL var yz=$.ajax ({type: ' post ', url: ' validatepwd2_checkpwd2?password2= ' +password2,
data:{}, Cache:false, DataType: ' JSON ', success:function (data) {if (data.msg = "false")/server return Back to False, change the value of ValidatePassword2 to Pwd2error, which is asynchronous, and needs to consider the return time {textpassword2.html ("<font color= ' red ' > Business password is not That's right!
</font> ");
$ ("#validatePassword2"). Val ("Pwd2error");
CheckPassword2 = false;
Return
}}, Error:function () {}}); 4.$.ajax the asynchronous request $.ajax ({URL: ' <%=request.getcontextpath ()%>/kc/kc_checkmernameunique.action ', type:
' Post ', data: ' Mername= ' +values, Async:false,//default to True asynchronous Error:function () {alert (' Error ');
}, Success:function (data) {$ ("#" +divs). HTML (data);
}
});