前台脚本中获取Session值的问题,急求!
--------------------编程问答-------------------- ajax --------------------编程问答-------------------- 本人新手,请给予具体代码示例指导,代码片段、demo或博客链接,谢谢。本人邮箱:free1985@163.com --------------------编程问答-------------------- 用ajax动态获取 --------------------编程问答-------------------- 请给出具体代码示例,谢谢 --------------------编程问答--------------------namespace WebApplication1
{
[AjaxNamespace("hehe")]
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
}
[AjaxPro.AjaxMethod]
public object GetDate()
{
return Session["name"];
}
}
}
前台JS
var da= hehe.GetDate().value;
web.config要加句话
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2" />
</httpHandlers>
在在项目中添加ajaxpro.2.dll的引用 --------------------编程问答-------------------- 在cs中用[webmethod]标注获取session值的方法,前台用jquery的ajax获取,这样应该可以的
--------------------编程问答-------------------- <%= Session["KEY"] %> 就可以了 何必用 AJAX --------------------编程问答--------------------
同意 --------------------编程问答-------------------- js与cs之间的交互只能能过get,post来完成
例如getSession.aspx?key=...
Response.Write(Session[Request["key"]]);
...
<script>
var test="kk";
jQuery.get('getSession.aspx?key='+ test,'',function(data){...});
</script> --------------------编程问答-------------------- 可以使用cookie解决.
后台写cookie的代码如下:
Response.Cookies["ID" + i.ToString()].Value = "test" + i.ToString();
前台读cookie的代码如下:
var arr = document.cookie.match(new RegExp("(^| )"+szTemp+"=([^;]*)(;|$)"));
if(arr != null)
{
document.getElementById("Label1").textContent = arr[2];
}
--------------------编程问答--------------------
http://topic.csdn.net/u/20101124/21/dc9f7a11-b4e1-4099-923c-895b2fb1d83d.html
补充:.NET技术 , ASP.NET