Development tools and key technology: Visual Studio 2015 & amp; & JQuery
Author: WeiYongGui
Time to write:
May 05, 2020
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
1, to get the data from the server to the page/jQuery
FunctionjqGetData () {
$. Ajax ({
Type: "get", [type]
Url: "/jQueryAjax getPersonInfor", [request address]
Async: true, set the asynchronous
DataType: "json" server returns the data type of the [expected]
Success: the function (data) {[is an object, along with the request sent to the server data]
$(" # txtName "). Val (data. Name);
$(" # cboSex "). Val (data. Sex);
$(" # txtAddress "). Val (data. The address);
}
})
}
2, the page data submitted to the server/jQuery
FunctionjqSubmitForm () {
Var name=$(" # txtName "). Val ();
Var sex=$(" # cboSex "). Val ();
Var address=$(" # txtAddress "). Val ();
If (name=="" | | sex==0 | | address==" ") {
Alert (" please check whether the data is complete ");
return false;
}
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 (); [serialize () sequence form content as the string, used for Ajax requests
]
Var arrData=https://bbs.csdn.net/topics/$(" # myform "). SerializeArray (); [serializeArray () serialized form elements (like 'serialize ()' method) returns a JSON data structure, data]
The console. The log (serData);
The console. The log (arrData);
$. Ajax ({
Type: "post", [type]
Url: "/jQueryAjax getDataByFormCollection", [request address]
Data: arrData, [is an object, along with the request is sent to the server data]
Success: the function (MSG) {[success: it is a way, after the success of the request of the callback function, the incoming data after the return, and a string containing success code]
Alert (MSG);
{}, error: function (XMLHTTP)
The console. The log (XMLHTTP);
}
})
}
3, in the jQuery $. The get () method and $. Post () method
Grammar: $. Get or $. Post (url, [data], [callback], [type])
Description: through remote HTTP GET or POST request loading information
Url: send a request address,
Data: sent the Key/value parameter,
The callback: send success callback function,
Type: return content format, XML, HTML, script, json, text, _default,
Using the $. Get () or $. Post method to get data from the server
FunctiongetFun () {
$.get ("/jQueryAjax getPersonInfor ", function (data) {
$(" # txtName "). Val (data. Name);
$(" # cboSex "). Val (data. Sex);
$(" # txtAddress "). Val (data. The address);
}, "json");
}
FunctionpostFun () {
$.post ("/jQueryAjax getDataByRequest frmData, function (MSG) {
$(" # txtName "). Val ();
$(" # cboSex "). Val ();
$(" # txtAddress "). Val ();
}, "json");
}
CodePudding user response:
The good, the collection,
CodePudding user response:
Collect the spare,