一个aspx页面,一个ashx页面,,怎么把ashx文件中的context.Response.Write("OK");传到前台的label显示啊?谢谢      public void ProcessRequest (HttpContext context) {
              string json = "OK";
             context.Response.Write(json); 需要把这个到前台显示!!
}
前台脚本
 <script type="text/javascript">
//        $(function () {
            $("#txtContents").blur(function () {
                $.post("Handler2.ashx", //要发送到的URL地址  以Post形式发送
        {"name": $("#txtContents").attr("value"), "user_id": $("#TextBox1").attr("value") }, //发送的Json数据 _name 对应Home/getJsonData方法中的参数名字
        function (data)  //回调函数 参数data : 返回的json数据
        {
           l aert(data);
  这里不弹出任何数据,貌似像是没返回任何数据一样
        },
        "json" //返回json类型数据
        );
            });
        });
        
    </script>JSON脚本

解决方案 »

  1.   

    应该至少返回错误吧。把datatype  "json" 去掉试一试,因为你返回的不是JSON. 在浏览器里 浏览你的ashx,看看是不是能返回。
      

  2.   

    或者用这种方式// Assign handlers immediately after making the request,
    // and remember the jqxhr object for this request
    var jqxhr = $.post("example.php", function() {
      alert("success");
    })
    .done(function() { alert("second success"); })
    .fail(function() { alert("error"); })
    .always(function() { alert("finished"); });看看是不是进入fail里面了。
      

  3.   

    你返回的不是json格式的数据,但是你dataType指定为json了,按照json解析出错就不会执行success回调了$.post("Handler2.ashx", //要发送到的URL地址  以Post形式发送
            {"name": $("#txtContents").attr("value"), "user_id": $("#TextBox1").attr("value") }, //发送的Json数据 _name 对应Home/getJsonData方法中的参数名字
            function (data)  //回调函数 参数data : 返回的json数据
            {
               l aert(data);
      这里不弹出任何数据,貌似像是没返回任何数据一样
            },
            "text" //去掉或者改为text或者html
            );