$(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").html(result);
},
error:function(){
alert('错误');
}
});
});
});
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里面的数据
$("#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").html(result);
},
error:function(){
alert('错误');
}
});
});
});
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',试试吧。
不知道是不是这段有问题
[Code]
string LoginType = Convert.ToString(context.Request.QueryString["LoginType"]);
string UserName = Convert.ToString(context.Request.QueryString["UserName"]);
string UserPwd = Convert.ToString(context.Request.QueryString["UserPwd"]);
[/Code]
string LoginType = Convert.ToString(context.Request.QueryString["LoginType"]);
string UserName = Convert.ToString(context.Request.QueryString["UserName"]);
string UserPwd = Convert.ToString(context.Request.QueryString["UserPwd"]);这段
$(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:"GET",
contentType: "application/json,charset=utf-8",
url:"/user/login.ashx",
data:"LoginType="+logintype+"&UserName="+username+"&UserPwd="+userpwd,
dataType: 'text',
success: function(result) { //回调函数,result,返回值
$("#Login").html(result);
},
error:function(){
alert('错误');
}
});
});
});把Type改成GET,data改成URL参数的形式就可以了,但是不知道为什么不能用POST和JSON数据