ASP.NET AJAX调用 WebService

时间:2022-11-12 14:48:03
同事的代码,帮忙修改的,为了实现页面跳转回来后,状态的保持,Service 使用了Session。

 主要的JS
$.ajax({
url: "/ws/StaffInfo.asmx/Note",//路径/方法
type: "POST",
contentType: "application/json",
data: "{id:'" + id + "',sex:'" + sex + "',dep:'" + dep + "',sql:'" + sql + "',page:'" + page + "'}",
dataType: "json",
success: function (res) {
//var th = res.d;
//alert(th);
window.open("AddStaffInfo.aspx?id=" + getid + "", "_self");
},
error: function (XMLHttpRequest, textStatus, errorInfo) {
alert("请求失败");
}
//error: function (data) {
// alert("请求失败");
//}
}); //此处使用 Session,必须加的特性
[WebMethod(EnableSession = true)]
public string Note(string id, string sex, string dep, string sql,string page)
{
Session["WebServiceStaffIsopen"] = true;
Session["WebServiceStaffId"] = id;
Session["WebServiceStaffSex"] = sex;
Session["WebServiceStaffDep"] = dep;
Session["WebServiceStaffPage"] = page; string s = Microsoft.JScript.GlobalObject.unescape(sql);
Web.StaffInfo.Id = id;
Web.StaffInfo.Sex = sex;
Web.StaffInfo.Dep = dep;
Web.StaffInfo.Sql = s;
Web.StaffInfo.Index = page;
Web.StaffInfo.Isopen = true;
if (s.Trim().ToLower() == "true")
{
Web.StaffInfo.Sql = "1=1";
Session["WebServiceStaffSql"] = "1=1";
}
else
{
Web.StaffInfo.Sql = s;
Session["WebServiceStaffSql"] = s;
}
return s + id + sex + dep + page; }