下面是我的Jquery代码,我想传递Session paramater,例如Session ["ID"].Jquery调用ASHX页面
以下所有参数都正常工作,session参数有一个值,但是如何从Jquery传递会话参数?
所以下面的代码"paramater Sessionparameter"应该替换为Session ["ID"]或类似的东西.我怎样才能做到这一点?
请指教?
$('input[name$=btnTab1Save]').click(
function (e) {
// debugger;
// AJAX call to the handler
$.post(
'Consulting.ashx',
// data to the handler in the form of QueryString
{
tab: 'tab1',
// id is the second column within the row
Ilac_id: prevRow.find('td:eq(0)').text(),
ID: SESSION_PARAMATER,
begindate: $('input[name$=begindate]').val(),
weigth: $('input[name$=weigth]').val(),
continue: true,
freq: $('input[name$=freq]').val(),
reason: $('input[name*=radListreason]:checked').val(),
freq2: $('input[name$=radListfreq2]:checked').val(),
freetext: $('input[name$=freetext]').val()
},
// callback function
// data is the JSON object
function (data) {
if (data.Success) {
// close the tab
}
},
"json"
);
});
Run Code Online (Sandbox Code Playgroud)
我可以读取我的参数,如Convert.Toint(context.Request.Form ["ID"]));
data.weigth = Convert.ToInt32(context.Request.Form["weigth"]);
Run Code Online (Sandbox Code Playgroud)
我试过了'<%= Session["ID"] .ToString() %>',但它没有用......
如果信息在会话中,ASHX可以直接访问会话内容.
你需要实施IReadOnlySessionState,你会没事的.
<% @ webhandler language="C#" class="MyClass" %>
using System;
using System.Web;
using System.Web.SessionState;
public class MyClass: IHttpHandler, IReadOnlySessionState
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write(ctx.Session["ID"]);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3148 次 |
| 最近记录: |