服务器端控件ajax请求
Posted Blogger
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了服务器端控件ajax请求相关的知识,希望对你有一定的参考价值。
//获取服务器端控件
$("#<%=txtTo.ClientID%>")或 $("[id$=‘txtTo‘]")
$("#<%=txtTo.ClientID%>")或 $("[id$=‘txtTo‘]")
//aspx调用ajax
$.ajax({
url: ("Demo.aspx?timestamp={0}").format(new Date().getTime()),
type: ‘POST‘,
dataType: ‘json‘,
timeout: 10000,
data: {
action: "GetUserByPhone",
phoneNumber: phone.val()
},
success: function (result) {
if (result.mes == "1") {
$("#<%=txtMemberName.ClientID%>").val(result.strMemberName);
}
else {
$.ajax({
url: ("Demo.aspx?timestamp={0}").format(new Date().getTime()),
type: ‘POST‘,
dataType: ‘json‘,
timeout: 10000,
data: {
action: "GetUserByPhone",
phoneNumber: phone.val()
},
success: function (result) {
if (result.mes == "1") {
$("#<%=txtMemberName.ClientID%>").val(result.strMemberName);
}
else {
if (confirm("<%=Resources.Admin.Tip_Inform_MobilePhone_Undefined_QuickRegistration %>")) {
location.href = ‘FastRegistration.aspx?NodeID=1029&phone=‘ + phone.val();
}
}
$("#<%=hidUserId.ClientID%>").val(result.strUserId);
},
error: function () {
$("#<%=txtMemberName.ClientID%>").val("");
$("#<%=hidUserId.ClientID%>").val("");
}
});
location.href = ‘FastRegistration.aspx?NodeID=1029&phone=‘ + phone.val();
}
}
$("#<%=hidUserId.ClientID%>").val(result.strUserId);
},
error: function () {
$("#<%=txtMemberName.ClientID%>").val("");
$("#<%=hidUserId.ClientID%>").val("");
}
});
//Demo.aspx 的page load方法加
string action = this.Request.Form["Action"];
if (!String.IsNullOrEmpty(action))
{
//发送短信验证码
this.Response.Clear();
this.Response.ContentType = "application/json";
string writeText = string.Empty;
switch (action)
{
case "GetUserByPhone":
writeText = this.GetUserByPhone();
break;
default:
break;
}
this.Response.Write(writeText);
this.Response.End();
}
string action = this.Request.Form["Action"];
if (!String.IsNullOrEmpty(action))
{
//发送短信验证码
this.Response.Clear();
this.Response.ContentType = "application/json";
string writeText = string.Empty;
switch (action)
{
case "GetUserByPhone":
writeText = this.GetUserByPhone();
break;
default:
break;
}
this.Response.Write(writeText);
this.Response.End();
}
//ajax请求调用一般处理程序
$.ajax({
type: "POST", //提交方式
url: "/Demo/Testing.ashx", //提交的页面/方法名
data: null, //参数(如果没有参数:null)
success: function (data) {
//返回的数据用获取内容
$.ajax({
type: "POST", //提交方式
url: "/Demo/Testing.ashx", //提交的页面/方法名
data: null, //参数(如果没有参数:null)
success: function (data) {
//返回的数据用获取内容
},
error: function (err) {
error: function (err) {
}
});
//刷新session
public class Testing: IHttpHandler, System.Web.SessionState.IRequiresSessionState
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string set = context.Session["Setting"].ToString();
});
//刷新session
public class Testing: IHttpHandler, System.Web.SessionState.IRequiresSessionState
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string set = context.Session["Setting"].ToString();
if (set == "0")
{
context.Session["Setting"] = 1;
}
else
{
context.Session["Setting"] = 0;
}
context.Response.Write("1");
}
{
context.Session["Setting"] = 1;
}
else
{
context.Session["Setting"] = 0;
}
context.Response.Write("1");
}
//ajax请求,一般处理程序返回json
$.ajax({
type: ‘POST‘,
async: false,
url: "../Handler/CheckPhone.ashx",
data: { "mobile": phone.val(), "Action": "addCompensate" },
success: function (a) {
num = a;
if (a == 0) {
$("#txtMobileTip").text(‘<%=Resources.Admin.Wrong_Undefined_MobilePhone %>‘);
return false;
}
}
});
public class CheckMobile : IHttpHandler,System.Web.SessionState.IRequiresSessionState
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request["Action"];
switch (action)
{
case "addCompensate":
CheckInBaseInfo(context);
break;
default:
break;
}
}
$.ajax({
type: ‘POST‘,
async: false,
url: "../Handler/CheckPhone.ashx",
data: { "mobile": phone.val(), "Action": "addCompensate" },
success: function (a) {
num = a;
if (a == 0) {
$("#txtMobileTip").text(‘<%=Resources.Admin.Wrong_Undefined_MobilePhone %>‘);
return false;
}
}
});
public class CheckMobile : IHttpHandler,System.Web.SessionState.IRequiresSessionState
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request["Action"];
switch (action)
{
case "addCompensate":
CheckInBaseInfo(context);
break;
default:
break;
}
}
private void CheckInBaseInfo(HttpContext context)
{
Maticsoft.BLL.Promoter.PromoterBaseInfo bllInfo = new BLL.Promoter.PromoterBaseInfo();
if (bllInfo.GetModelByMobile(context.Request["mobile"])!=null)
{
context.Response.Write("1"); //存在
}
else
{
context.Response.Write("0"); //不存在
}
}
{
Maticsoft.BLL.Promoter.PromoterBaseInfo bllInfo = new BLL.Promoter.PromoterBaseInfo();
if (bllInfo.GetModelByMobile(context.Request["mobile"])!=null)
{
context.Response.Write("1"); //存在
}
else
{
context.Response.Write("0"); //不存在
}
}
以上是关于服务器端控件ajax请求的主要内容,如果未能解决你的问题,请参考以下文章
学习AJAX必知必会~Ajax基本使用,设置请求行请求体请求头,服务端响应JSON数据