俺用的jquery的ajax方法.先贴下js里的代码
$.ajax({
type: "GET",
url: "/market/user/logon/Default.aspx",
data: "username="+username....由于此处参数过多,略之。这里参数肯定没有问题
success: function onreg(data,textStatus){
alert("data="+data);
},
complete:function(XMLHttpRequest, textStatus){
alert("message="+XMLHttpRequest.status);
//alert("message="+XMLHttpRequest.readyState)
},
error: function myerr(mymsg){
alert("error="+mymsg);
}
});
贴出后台Default.aspx.cs文件代码
void Reguser()
{
string username = Request.QueryString["username"].ToString();
string password = Request.QueryString["password"].ToString();
string realityName = Request.QueryString["realityName"].ToString(); //联系人
string country = Request.QueryString["ContryCN"].ToString(); //国家
string area = Request.QueryString["provinceID"].ToString(); //省份
string city = Request.QueryString["cityID"].ToString(); //地区
string addres = Request.QueryString["addres"].ToString();
string companyName = Request.QueryString["companyName"].ToString(); //公司名称
string email = Request.QueryString["email"].ToString();
string sex = Request.QueryString["sexValue"].ToString(); //性别
string tell = Request.QueryString["tell"].ToString(); //座机号码
string mobile = Request.QueryString["mobile"].ToString();//手机
string ddBtype = Request.QueryString["BtypeID"].ToString();//行业大类
string ddsBtype = Request.QueryString["BstypeID"].ToString(); //行业小类
string product = Request.QueryString["likiContent"].ToString();//主营产品
userdetail.UserName = username;
userdetail.Password = password;
userdetail.CompanyPer = realityName;
userdetail.Country = country;
userdetail.Area = area;
userdetail.City = city;
userdetail.Address = country + area + city + addres;
userdetail.CompanyName = companyName;
userdetail.Mail = email;
userdetail.BType = Convert.ToInt32(ddBtype);
userdetail.SType = Convert.ToInt32(ddsBtype);
userdetail.Product = product;
userdetail.Sex = sex;
userdetail.Tel1 = tell;
userdetail.Mobile = mobile;
if (UserOperator.InsertUser(userdetail))
{
Response.Write("11");
Response.End();
}
else
{
Response.Write("22");
Response.End();
}
}
方法在页面Page_Load()时调用
if (!IsPostBack)
{
Reguser();
}
问题:提交数据-->后台接收-->插入数据(UserOperator.InsertUser()方法)-->返回前台
(Response.Write())-->前台响应事件(complete和error)success没有响应。但是数据已完整插入数据库里,
用alert()输出XMLHttpRequest的readyState的值为4,输出status的值为0.我用同样的方法验证用户是否存在就没有任
何问题,我的InsertUser()方法,插入成功返回true,失败返回false,先不说我插入成功了,就算是我插入失败了,else也返回了个
22给我呀..输出status咋就是0呢?我仔细检查了传入的每一个参数,可以确保没有错误.望高手指点迷津,小弟调试二天了,寝室难安呀.
success: function onreg(data,textStatus)
方法function后面不要加onreg,再试试。~~~~