ajax post传值
一、字符串
$.ajax({
type: "POST",
data: {"ID":id,"name":name},
url: "/XX/XXX/XXXX",
cache: false,
success: function (result) {
if (result > 0) {
alert("保存成功!");
}
else {
alert("保存失败,请稍后再试!");
}
}
});
后台 XXXX(string ID,string name){} //ID、name
二、实体类
var data = {};
data["ydayScheduleCount"] = $("#ydayScheduleCount").val();
data["ydayRealCount"] = $("#ydayRealCount").val();
data["ydayCancelCount"] = $("#ydayCancelCount").val();
data["ydayDelayCount"] = $("#ydayDelayCount").val();
data["ydayDelayTwoCount"] = $("#ydayDelayTwoCount").val();
data["ydayFlightNormalRate"] = $("#ydayFlightNormalRate").val();
data["ZBAAScheduleCount"] = $("#ZBAAScheduleCount").val();
data["ZBAARealCount"] = $("#ZBAARealCount").val();
data["ZBAACancelCount"] = $("#ZBAACancelCount").val();
data["ZBAADelayCount"] = $("#ZBAADelayCount").val();
data["ZBAADelayTowCount"] = $("#ZBAADelayTowCount").val();
data["ReMarkA"] = $("#ReMarkA").val();
data["ReMarkB"] = $("#ReMarkB").val();
data["ReMarkC"] = $("#ReMarkC").val();
data["ReMarkD"] = $("#ReMarkD").val();
data["ReMarkE"] = $("#ReMarkE").val();
data["ReMarkF"] = $("#ReMarkF").val();
$.ajax({
type: "POST",
data: data,
url: "/XX/XXX/XXXX",
cache: false,
success: function (result) {
if (result > 0) {
alert("保存成功!");
}
else {
alert("保存失败,请稍后再试!");
}
}
});
后台 XXXX(CpyNightNew gnn){} //gnn 实体类
三、集合
var _list = {};
for (var air in airport) {
_list["runinfo_airport_racc[" + air + "].Airport"] = airport[air];
_list["runinfo_airport_racc[" + air + "].ActualCount"] = $("#" + airport[air] + "_ActualCount_Z").val();
_list["runinfo_airport_racc[" + air + "].NormalRate"] = $("#" + airport[air] + "_NormalRate_Z").val();
_list["runinfo_airport_racc[" + air + "].Delays"] = $("#" + airport[air] + "_Delays_Z").val();
_list["runinfo_airport_racc[" + air + "].ProblemCauses"] = $("#" + airport[air] + "_ProblemCauses_Z").val();
_list["runinfo_airport_racc[" + air + "].Days_Type"] = "Z";
_list["runinfo_airport_racc[" + air + "].isair"] = 1;
}
$.ajax({
url: '/XX/XXX/XXXX',
data: _list,
dataType: "text",
type: "POST",
traditional: true,
success: function (responseJSON) {
if (responseJSON > 0) {
alert("更新成功!");
}
else {
alert("更新失败,请稍后再试!");
}
}
});
后台 XXXX(List<runinfo_airport_racc> runinfo_airport_racc) //runinfo_airport_racc 集合
四、json
//获取整表数据
function GetAllTableDate() {
var tr = $("#tb_duty").find("tr");
var week = 1;
var arraySaveDate = new Array();//存放数据的list
var objDate = new Object;//存放数据的每个model
var arr = ["onduty_name", "onduty_title", "onduty_contract", "onduty_week", "onduty_group"];
$.each($(tr), function () {
var tdArr = $(this).children();
objDate.onduty_name = tdArr.eq(1).find("input").val();//值班领导
objDate.onduty_title = tdArr.eq(2).find("input").val();//职务
objDate.onduty_contract = tdArr.eq(3).find("input").val();//联系方式
objDate.onduty_week = week;
objDate.onduty_group = 0;
arraySaveDate.push(objDate);
objDate = new Object();
objDate.onduty_name = tdArr.eq(4).find("input").val();//值班领导
objDate.onduty_title = tdArr.eq(5).find("input").val();//职务
objDate.onduty_contract = tdArr.eq(6).find("input").val();//联系方式
objDate.onduty_week = week;
objDate.onduty_group = 1;
arraySaveDate.push(objDate);
objDate = new Object();
objDate.onduty_name = tdArr.eq(7).find("input").val();//值班领导
objDate.onduty_title = tdArr.eq(8).find("input").val();//职务
objDate.onduty_contract = tdArr.eq(9).find("input").val();//联系方式
objDate.onduty_week = week;
objDate.onduty_group = 2;
arraySaveDate.push(objDate);
objDate = new Object();
week++;
});
return JSON.stringify(arraySaveDate);
}
function save(isSave)
{
$.ajax({
type: "POST",
dataType: "text",
url: "/ShareMethod/SaveDutyPlan",
data: { "strDutyPlan": GetAllTableDate(), "isSave": isSave },
success: function (result) {
alert(result);
}
})
}
后台
public string SaveDutyPlan(string strDutyPlan,bool isSave){
//页面传递数据集
List<onduty_info> lst_onduty_info = JsonConvert.DeserializeObject<List<onduty_info>>(strDutyPlan);
}