问题描述
- 求教为何接收不到参数。。
-
else {
$.ajax({
type: "POST",
url: "addXZYW.aspx/SetBaoCun",
//data: {id: id, mc: mc, mc: mc,engname: engname,shuruma: shuruma,tym: tym},data: "{id:'" + id + "',mc:'" + mc + "',engname:'" + engname + "',shuruma:'" + shuruma + "',tym:'" + tym + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (data) { }
});
};这样后台怎么收不到数据呢? 后台: [System.Web.Services.WebMethod] public void SetBaoCun(string id, string mc, string engname, string shuruma,string tym) { //string id1 = id; string mc1 = mc; string engname1 = engname; string shuruma1 = shuruma; string tym1 = tym; string sql = string.Format(@"insert into zsk_yaopin(id,name,engname,shuruma1,commonname) values({0},{1},{2},{3},{4})", id, mc, engname, shuruma, tym); DbAccess.ExecuteNonQuery(DbAccess.m, CommandType.Text, sql); }
解决方案
参数这样传:
data: {
id: id ,
mc:mc,
engname:engname,
shuruma:shuruma,
tym:tym
}
后台可以这样:方法名(FormCollection formInfos){
tring id = formInfos["id"].Trim();//以此类推
}
解决方案二:
SpringMVC 接收对象参数
springMVC接收对象参数
Flex 接收外部参数
----------------------
解决方案三:
data: "{id:'" + id + "',mc:'" + mc + "',engname:'" + engname + "',shuruma:'" + shuruma + "',tym:'" + tym + "'}",传参不用加“变字符串
解决方案四:
传参时最好不要加字符串
解决方案五:
data: {
id: id ,
mc:mc,
engname:engname,
shuruma:shuruma,
tym:tym
}