First: Get delivery
Foreground Ajax Get delivery: That is, after the requested address plus parameters, url address length is displayed, low security
Background receive: request.querystring["parameter name"]!
For example:
function Loadbar (ID) {
var project = ID;
var month = $ ("#txtMonth"). Val ();
$.ajax ({
type: "Get",
async:false,
url: ' getprojectscore.aspx?project= ' + project + ' &month= ' + month,
dataType: ' json ',
beforesend:function () {
},
success:function (msg) {
if (msg)
{ OptionBar.xAxis.categories = eval (msg.projectscore.orgname);
Optionbar.series = eval (msg.projectscore.series);
var t = eval ("+ subtitle +"));
Optionbar.subtitle = T.subtitle;
Chart = new Highcharts.chart (Optionbar);
}
,
error:function () {
alert (' Error! ');
}}
);
The second type: Post delivery
2.1 Strings passed as parameters
That is, the parameters passed are passed in the form of a string. Datatype= "Text";
Foreground Ajax POST Delivery: A request to submit the form data to the server, and the data to be submitted is in the entity behind the header of the message.
Background receive: request.form["parameter name"]
For example:
$ ("Input[name=returnfile]"). Click (function () {
var Returnflag = $ (this). Val ();
var guid = $ (this). Prev (). html ();
$.ajax ({
type: "POST",
async: "false",
URL: "returndata.aspx",
data: "flag=" + Returnflag + & Guid= "+guid+" ",
success:function () {
}
});
})
Background receive:
String flag=request.form["flag"];
String guid=request.form["GUID"];
2.2 JSON as a parameter pass
The parameters passed are passed in the form of a JSON string. Datatype= "JSON";
Foreground Ajax POST Delivery: A request to submit the form data to the server, and the data to be submitted is in the entity behind the header of the message.
Background receive:
StreamReader reader=new StreamReader (Request.inputstream);
String str = reader. ReadToEnd ();
For example:
$ ("Input[name=returnfile]"). Click (function () {
var Returnflag = $ (this). Val ();
var guid = $ (this). Prev (). html ();
var str = ' {' flag ': ' + Returnflag + ', ' guid ': ' + GUID + '} ';
var json = eval ("+ JSON +"));
$.ajax ({
type: "POST",
async: "false",
URL: "khdf_returndata.aspx",
dataType: "JSON"
data: JSON,
success:function () {
}
});
Background receive:
StreamReader reader=new StreamReader (Request.inputstream);
String str = reader. ReadToEnd ();
After reading Newtonsoft do JSON processing
2.3 JSON as a parameter pass
$ (function () {
$ (' #btnLogin '). Click (function () {
//var username = $ ("#txtUserName"). Val ();
var password = $ ("#txtPassword"). Val ();
var paras = "Username=" + username + "&password=" + password;
Alert (paras);
var data = {
Username: $ ("#txtUserName"). Val (),
password:$ ("#txtPassword"). Val ()
}
$.post ("home/ Checklogin ", data, function (data) {
alert (data)})
})
If you follow 2.2post. You must add: ContentType: "Application/json"
Background receive:
[HttpPost]
Public ActionResult checklogin (string username,string password)
{
string name = Username;
string pwd = password;
return View ();
}
The above is a small series for you to bring the asp.net jquery ajax pass the parameters of the instance of all the content, I hope that we support the cloud-Habitat Community ~