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();//以此類推
}