- JScript code
$(document).ready(function(){ $("#UserLogin").click(function(){ var logintype=$("#LoginType").val(); var username=$("#UserName").val(); var userpwd=$("#UserPwd").val(); if(username=='') { alert('请输入用户名!'); return false; } if(userpwd=='') { alert('请输入密码!'); return false; } $.ajax({ type:"POST", contentType: "application/json", url:"/user/login.ashx", data:"{LoginType:"+logintype+",UserName:"+username+",UserPwd:"+userpwd+"}", dataType: 'json', success: function(result) { //回调函数,result,返回值 $("#Login")(result); }, error:function(){ alert('错误'); } }); });});
- C# code
IUserLogin userlogin = new IUserLogin(); public void ProcessRequest(HttpContext context) { string LoginType = Convert.ToString(context.Request.QueryString["LoginType"]); string UserName = Convert.ToString(context.Request.QueryString["UserName"]); string UserPwd = Convert.ToString(context.Request.QueryString["UserPwd"]); UserInfo info = new UserInfo(); if (LoginType == string.Empty || LoginType == null || LoginType == "") context.Response.Write("参数错误!"); if (LoginType == "id") info.Userid = Convert.ToInt32(UserName); if (LoginType == "user") info.UserName = UserName; if (LoginType == "email") info.Email = UserName; info.UserPwd = UserPwd; context.Response.Write(userlogin.UserLogin(LoginType, info)); }
对jquery ajax不熟,麻烦大侠帮忙看看,JS哪里出错了,老是只执行error里面的数据
------解决方案--------------------------------------------------------
首先,确认你项目发布在IIS上了,我看你url是从根目录开始的
然后,把data改成这种形式:'{str:"' + $(this).val() + '"}';
dataType: 'json', 改成 dataType: 'text',
试试吧。。。。
------解决方案--------------------------------------------------------
饿 是不是没有response.end()的缘故,所以把整个html页发送出去了