Web form ajax请求

1.添加web应用程序

2.添加web窗体

web窗体Demo

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebForm_Ajax调用.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btn1" value="点击触发Ajax"/>
</div>
</form>
<div id="div1"></div>
</body>
</html>
<script src="Scripts/jquery-1.8.2.min.js"></script>
<script>
$("#btn1").click(function () {
$.ajax({
type: 'post',
url: '/Handler/Handler1.ashx',
data: {
ids:1
},
success: function (da)
{
$("#div1").html(da);
}
})
})
</script>

接下来是创建一般处理程序

一般处理程序中ajax所请求的Demo

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int ids = int.Parse(context.Request["ids"]);
string name = null;
if (ids == 1)
{
name = "Hellow World!";
}
else
{
name = "Sorry!";
}
context.Response.Write(name);
}

原文地址:https://www.cnblogs.com/gsh0921/p/6593188.html