日期:2014-05-17  浏览次数:20376 次

asp.net 简单问题 求解
大家好  我想练习个简单的 ajax的登录  但是 老是打不到我想要的结果

但是 朋友的电脑上可以显示   我不知道具体是什么原因造成的  希望大家指点下!谢谢!

Default.aspx中:js
    <script type="text/javascript">
        var xmlhttp;
        var result; 
        function btn_logn_Clock() {
            var userName = document.getElementById("username").value;
            var userPwd = document.getElementById("password").value;
            xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); 
            var data = "username=" + encodeURIComponent(userName)
                         + "&password=" + encodeURIComponent(userPwd);
            xmlhttp.open("Post", "Default2.aspx", true);
            xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    result = xmlhttp.responseText;
                }
            }
            xmlhttp.send(data); 
        }
    </script>


Default2.aspx.cs中
 protected void Page_Load(object sender, EventArgs e)
    {
        string userName = string.Empty;
        string password = string.Empty;
        userName = Request.Form["username"];
        password = Request.Form["password"];
        Response.Write("姓名:’" + userName + "'<br/>  密码:" + password);
        Response.End();
    }


谢谢大家!
------解决方案--------------------
帮你简单测试了一下你的代码:在IE和chrome下都运行正常,ajax请求响应都正常。

会不会Chrome里需要设置什么呢?你在IE下运行正常吗?