【发布时间】:2011-04-06 00:50:31
【问题描述】:
我需要通过使用 jQuery 调用 PageMethod 来设置几个 Session 变量。
客户端js长这样:
function setSession(Amount, Item_nr) {
//alert(Amount + " " + Item_nr);
var args = {
amount: Amount, item_nr: Item_nr
}
//alert(JSON.stringify(passingArguments));
$.ajax({
type: "POST",
url: "buycredit.aspx/SetSession",
data: JSON.stringify(args),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert('Success.');
},
error: function () {
alert("Fail");
}
});
}
和服务器端是这样的:
[System.Web.Services.WebMethod(EnableSession = true)]
public static void SetSession(int amount, int item_nr)
{
HttpContext.Current.Session["amount"] = amount;
HttpContext.Current.Session["item_nr"] = item_nr;
}
只是,似乎没有设置会话变量。当我尝试 Response.Write 出会话变量时,我什么也没得到。我没有收到任何错误,我可以提醒从 onclick 事件传递给 js 函数的值,所以它们就在那里。
谁能看看我是否遗漏了什么?
谢谢
【问题讨论】:
标签: jquery asp.net session pagemethods