菜鸟提问,ajax执行不了,是什么情况

Miracle_lucy 2014-07-10 03:30:25
 <script type="text/javascript">    
$(function () {
$("#login").click(function () {
var strname = $("#txtname").val();
var strpwd = $("#txtpwd").val();
debugger;
$.ajax({
url: "page70.aspx",
type: "POST",
data:{name:encodeURI(strname),pwd:encodeURI(strpwd)},
success: function (result) {
if (result == true) {
$("#tips").html("登录成功!!");
}
else {
$("#tips").html("登录用户名或密码有错误!!")
}
}
});

});

});
</script>
</head>
<body>
<form id="myform">
<input type="text" name="name" id="txtname" />
<input type="text" name="password" id="txtpwd" />
<input type="button" value="登录" id="login" />
<input type="button" value="重置" id="reset" />
</form>
<div id="tips">
</div>
</body>


调试的时候,根本不执行ajax(),就直接跳出来了,是什么原因
...全文
94 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Miracle_lucy 2014-07-11
  • 打赏
  • 举报
回复
哈哈 解决了 可以执行的 昨天是一直返回结果“登录用户名或密码有错误”
 <script type="text/javascript">    
        $(function () {
            $("#login").click(function () {
                var strname = $("#txtname").val();
                var strpwd = $("#txtpwd").val();
                debugger;
                $.ajax({
                    url: "page70.aspx",
                    type: "POST",
                    data:{name:encodeURI(strname),pwd:encodeURI(strpwd)},
                    success: function (result) {
                        if (result ) {
                            $("#tips").html("登录成功!!");
                        }
                        else {
                            $("#tips").html("登录用户名或密码有错误!!")
                        }
                    }
                });
           
            });
 
        });
    </script>
JFMark 2014-07-11
  • 打赏
  • 举报
回复




$(document).ready(function(){
          $("#login").click(function () {
                var strname = $("#txtname").val();
                var strpwd = $("#txtpwd").val();
                debugger;
                $.ajax({
                    url: "page70.aspx",
                    type: "POST",
                    data:{name:encodeURI(strname),pwd:encodeURI(strpwd)},
                    success: function (result) {
                        if (result == true) {
                            $("#tips").html("登录成功!!");
                        }
                        else {
                            $("#tips").html("登录用户名或密码有错误!!")
                        }
                    }
                });
           
            });
 
        });


可能页面没缓冲好就绑定click了
  • 打赏
  • 举报
回复
你怎么知道它没有执行ajax啊?
tony4geek 2014-07-10
  • 打赏
  • 举报
回复
出什么错误啊 。调试看看

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧