JavaScript 中的ajax提交请求
$.ajax({ // 提交地址 url: "", // 提交的数据 data: { key1: value1, key2: value2, key3: value3, key4: value4 }, // 提交前事件 beforeSend: function () { login.hide(); showInfo.html(loginInfo); }, // 提交方式 type: "POST", // 提交的数据类型 dataType: "json", // 提交成功后事件 success: function (result) { if (result.State.toString() == "success" && result.IsLogin.toString() == "1") { showInfo.addInfoMsg("登录成功!正在跳转. . ."); window.location.href = "/Default.aspx"; } else { login.show(); showInfo.addShowMsg(result.exMsg.toString()); } }, // 提交错误时间 error: function (httpRequest, textStatus, errorThrown) { showInfo.addShowMsg("系统出错,请重新登录!"); login.show(); } });
返回的数据格式:
// 返回的数据格式 一下 var returnInfo = ""State":"{0}","IsLogin":"{1}","exMsg":"{2}""; context.Response.Write("{" + String.Format(returnInfo, "success", "1", "登录成功!") + "}"); context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "用户名不能为空") + "}"); context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "密码不能为空") + "}"); context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "您没有登录系统的权限,请联系贵公司管理员.") + "}"); context.Response.Write("{" + String.Format(returnInfo, "fail", "0", "非法登陆," + ex.Message + "}"));