1、js方法
<img src="/guangang_cool/blog/images/login/loginr_07.gif" onclick="createuser();"
width="138" />
2、添加js方法
function createuser() {
if ($("#emailinfo").html().indexOf("Email地址合法") == -1) {
checkregemail();
changeimg();
return false;
}
if ($("#spanRegtype").val() == "1") {
if ($("#mobileInfo").html().indexOf("手机号合法") == -1) {
checkregMobile();
changeimg();
return false;
}
}
if ($("#repasswordinfo").html().indexOf("密码输入合法") == -1) {
recheckpassword();
changeimg();
return false;
}
if ($("#validateinfo").html().indexOf("验证码输入正确") == -1) {
checkvalidecode();
changeimg();
return false;
}
var $bday = "NULL";
var $mobile = $("#txtMobile").val();
var $cardid = $("#year").val();
var $answer = $("#txtanswer").val();
//开始注册用户
get传参:
$.ajax({//ajax调用传参
url: "/ajax.aspx?q=createuser&email=" + $("#txtemail").val() + "&mobile=" + $mobile + "&password=" + $("#txtpassword").val() + rand(100000, 999999) + "®type=" + $("#spanRegtype").val() + "&cardid=" + $cardid + "&answer=" + encodeURIComponent($answer) + "&time=" + new Date().toString(),
type: "GET",
timeout: 30000,
beforeSend: function() {
$("#status").html("正在注册中...");
},
error: function() {
$("#status").addClass("redr");
$("#status").html("注册用户失败,请重试或联系管理员!");
},
success: function() {
var $status = arguments[0]; //得到返回值
if ($status > 0) {
window.location = ($("#referurl").val());
}
else {
$("#status").addClass("redr");
$("#status").html("注册成功");
alert("注册成功");
window.location = $("#fromurl").val();
}
}
});
post传参:
$.ajax({
url: "/ajax.aspx?",
data: {
"q": "saveAddSKU",
"eid": eid,
"skulist": skulist,
"skunum": skunum,
"skupic": skupic,
"picbs": picbs,
"skupicnum": skupicnum,
"time": new Date().toString()
},
type: "POST",
timeout: 50000,
beforeSend: function() {
},
error: function() {
alert("SKU追加失败");
},
success: function(res) {
if (res == "0") {
alert("SKU追加成功");
}
}
});
}
3、ajax方法
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
switch (q)
{
#region 根据参数不同,进行不同的操作
case "checkemail"://检测邮箱是否可用
checkRegInfo(0);
break;
case "checkloginname"://检测用户名是否可用
checkRegInfo(1);
break;
case "checkmobile"://检测手机号是否可用
checkRegInfo(2);
break;
case "createuser"://注册用户
createuser();
break;
#endregion
}
}
}
#region 注册用户 对数据进行添加
private void createuser()
{//调用存储过程实例
string email = Fetch.Get("email"); //Fetch 分装类
string password = Fetch.Get("password");
string mobile = Fetch.Get("mobile");
string temp = password.Substring(0, password.Length - 6);
int regfrom = 0;
string question = Fetch.Get("cardid");
string rettype = Fetch.Get("regtype");
string answer = Fetch.Get("answer");
string userip = Page.Request.UserHostAddress;
int result = 0;
string msg = string.Empty;
iuser.regUser("", temp, rettype, mobile, email, regfrom, userip, question, answer, out result, out msg);
string itemp = result.ToString() + "@" + msg;
password = password.Substring(0, 6);
password = Common.Text.MD5(password);
DataSet ds = iuser.sp_login(email, password, Fetch.UserIp, out result, out msg);
if (ds != null && ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
commonfunction.SaveLoginCookie(dt.Rows[0]);
}
Response.Write(itemp); //打印返回值
Response.End();
}
#endregion
如果觉得《ajax使用流程【ajax详细使用步骤 ajax使用实例】》对你有帮助,请点赞、收藏,并留下你的观点哦!