JQuery induction summary
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key technology: Adobe Dreamweaver JavaScript
Author: Huang Futao
Writing time: on May 3, 2020,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
1 syntax:
JQuery. Ajax method ([setting])
Setting represents the optional value, and it is used to configure the Ajax request the keys to the collection of
2, some parameters of the Ajax (key and value)
(1) type that represents the submit type, when use through what way can submit through the type attribute value GET or POST submitted, submitted by default for the GET, for example: type: "GET"
(2) url: send a request address, when the data request after need to submit the data controller, through this property can be set to submit address
For example: url: "/jQueryAjax getPersonInfor" [the first name as controller, the second for the controller method name]
Asynchronous, (3) async: are set to the default value is true (asynchronous), when using asynchronous, and you don't write the words of code can be omitted when using synchronization, is set to false, synchronization must wait until the other request is completed to perform operations, such as: async: true,
(4) the dataType: expect the server returns the data type of the, if not specified, the jQuery automatically according to the HTTP packet MIME information intelligent judgment,
Generally we use the json format, can be set to "json", for example: dataType: "json",
5. Success: it is a method, the callback function after the request is successful, the incoming data after the return, and a string containing success code
6. Error: is a method and request failure is call this function, the incoming XMLHttpRequest object
Serialize () by the method can be serialized form content as the string
SerializeArray () serialized form elements (like 'serialize ()' method) returns a JSON data structure,
Note: this method returns a JSON object rather than a JSON string, you need to use a plug-in or a third-party library to string operation
Returns a JSON object is composed of an array of objects, each object contains one or two of value on - the name and value parameters
2, the form often use the block of code
1) custom variables to obtain form content
Var name=$(" # txtName "). Val ();
Var sex=$(" # cboSex "). Val ();
Var address=$(" # txtAddress "). Val ();
(2) whether the data complete
If (name=="" | | sex==0 | | address==" ") {
Alert (" please check whether the data is complete ");
return false;
}
(3) splicing character, and through the serialization methods serialized form
Var frmdata="https://bbs.csdn.net/topics/name=" + name + "& amp; Sex="+ +" sex & amp; Address="+ address;
Var serData=https://bbs.csdn.net/topics/$(" # myform "). The serialize ();
Var arrData=https://bbs.csdn.net/topics/$(" # myform "). SerializeArray ();
(4) by the method of ajax from the server to get data
$. Ajax ({
Type: "get",
Url:/jQueryAjax getPersonInfor,
Async: true,
DataType: "json",
Success: the function (data) {
console.log(data);
$(" # txtName "). Val (data. Name);
$(" # cboSex "). Val (data. Sex);
$(" # txtAddress "). Val (data. The address);
}
})
Ajax (5) by the data submitted to the controller, and return to prompt
$. Ajax ({
Type: "post",
Url:/jQueryAjax getDataByFormCollection,
Data: arrData,
//dataType: 'json'
Success: the function (MSG) {
Alert (MSG);
},
Error: function (XMLHTTP) {
The console. The log (XMLHTTP);
}
})
}