我需要通过使用jQuery调用PageMethod来设置几个Session vars。在PageMethod中设置会话(asp.net)
客户端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函数的值,所以它们在那里。
任何人都可以看到我是否错过了什么?
日Thnx