救教:html+Jquery+aspx的调用及返回值问题

pyjwnnit 2014-10-13 07:42:05
 $("#submitBtn").click(function(){
var formValue = $("#loginForm").serialize();
$.ajax({ url: "http://localhost:20874/Login.aspx", context: formValue, success: function(data){
if (data=="error")
{
alert('输入的用户或密码错误! 请查正好再重新操作');
}
}});
});

c#
//执行登录 参数说明   
Login_Exe(Request["userName"], Request["userPW"], Request["userType"]);


[WebMethod]
private static string Login_Exe(string userName, string userPW, string userType)
{
if (error)
return "error";
else
return "ok"

------------------
---------------------------------------------------------------------
以上方法 返不回 error 字符串, 晕哟。 返回的是整个页面的 aspx 页的HTML 码
谁帮看看。解决返回值问题
...全文
210 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pyjwnnit 2014-10-16
  • 打赏
  • 举报
回复
多谢各位, 搞定了, 发分!
Go 旅城通票 2014-10-14
  • 打赏
  • 举报
回复
而且你数据都配置错了,是data,不是content $("#submitBtn").click(function () { var formValue = $("#loginForm").serialize(); $.ajax({ url: "http://localhost:20874/Login.aspx", data: formValue, success: function (data) { if (data == "error") { alert('输入的用户或密码错误! 请查正好再重新操作'); } } }); return false }); 不知道你的是什么按钮,如果是submit在表单里面还会导致表单被提交,要return false阻止表单提交
Go 旅城通票 2014-10-14
  • 打赏
  • 举报
回复
去掉webmethod,response.end结束输出,不要return
Login_Exe(Request["userName"], Request["userPW"], Request["userType"]);
 
 

        private static  string Login_Exe(string userName, string userPW, string userType)
        {
                  if (error)
                      Response.Write("error");
                  else
                     Response.Write("ok");

                     Response.End();/////////
        }
Null_Reference 2014-10-14
  • 打赏
  • 举报
回复

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script src="Scripts/jquery-1.7.1.min.js"></script>
    <title></title>
    <script type="text/javascript">
        $(function () {
            $("#btnlogin").click(function () {
                var uname = $("#uname").val();
                var pwd = $("#pwd").val();
                $.ajax({
                    url: "http://localhost:6016/return.aspx",
                    type: "post",
                    data: {"uname":uname,"pwd":pwd},
                    success: function (result) {
                        $("#tips").text(result);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <input type="text" id="uname" name="uname" />
    <input type="password" id="pwd" name="pwd"/>    
    <input type="button" value="登录" id="btnlogin"/>
    返回数据:<span id="tips" style="color:red;"></span>
</body>
</html>

aspx页面除了顶部的一行代码,其它全部删掉 后台代码:


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                string uname = Request["uname"];
                string pwd = Request["pwd"];
                Response.Write("OKorError");
            }
        }
        
pyjwnnit 2014-10-13
  • 打赏
  • 举报
回复
我再补充一下: JQUERY 是在一个html 文件 它调用 aspx 文件。 返回值, 返回到html文件

52,797

社区成员

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

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