日期:2014-05-16  浏览次数:20689 次

为什么数据发送不到后台呢?
这个是存放在页面中的
    <script type="text/javascript">
        $(document).ready(function () {
            $("#username").blur(function () {
                var name = document.getElementById("username").value;
                var theName = escape(name);
                $.post("A2.ashx", { username: theName },
                    function (data) {
                        alert(data);
                    });
            });
        });
    </script>


下面是ashx的,为什么在ashx设置了断点,每次运行都跑不到ashx的断点呢
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string name = context.Request.QueryString["username"];
        string result = "denied";
        if (name == "t")
        {
            result = "okay";
        }
        context.Response.Write(result);
    }


------解决方案--------------------
你是在vs中调试还是通过iis?

通过iis需要附加aspnet_wp.exe进程才行。参考:VS2008无法断点调试程序

并且你指定为post提交,用get方法获取不到数据的
        $(document).ready(function () {
            $("#username").blur(function () {
                var name = document.getElementById("username").value;
                //var theName = escape(name);//这里不用编码了,指定数据为json对象jq会自动调用encodeURIComponent帮你编码的
                $.post("A2.ashx", { username: theName },
                    function (data) {
                        alert(data);
                    });
            });
        });