- JScript code
$.ajax({ type: "POST", url: "ValueChange.ashx", data: { sm: logInfo }, contentType: "application/text; charset=utf-8", success: function() { var session = '<%=Session["aa"]%>'; alert(session); return true; } });
- C# code
using System;using System.Collections;using System.Data;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Xml.Linq;using System.Web.SessionState;namespace ValueChangePro{ /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Handler1 : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; var log = context.Request.QueryString["sm"]; context.Session["aa"] = log; } public bool IsReusable { get { return false; } } }}
在一般处理性文件中无法获取传递过来的sm ,firebug调试的时候可以看到他的参数
sm=TextBox2%EF%BC%9A+%E7%94%B1+%22%22++%E8%A2%AB%E4%BF%AE%E6%94%B9%E4%B8%BA++%22sdfsd%22%0A
程序alert sm的值 确实是有值的 但是就是获取不到
------解决方案--------------------------------------------------------
data: { "sm": logInfo },
var log = context.Request.Params.Get("sm");
或
var log = context.Request.Form["sm"];