wordpress sns/知乎seo排名帝搜软件
这是使用ajax加上.ashx来进行结合的一个非常简单的登录小例子,
主要不在于例子,在于这个方法,体现ajax的一种模式,千万别忘了引用jquery,
ashx代码,用Response 与Request
public class Handler1 : IHttpHandler{public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";string nam= context.Request["na1"];string nam1 = context.Request["na2"];if (nam=="123" && nam1=="123"){context.Response.Write("1");}}public bool IsReusable{get{return false;}}}
这是前端代码,注意不是webform,只是html界面。
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /><title></title><script src="jquery-3.4.1.js"></script> <script type="text/javascript">$(function () {$("#te3").click(function () {var a = $("#te1").val();var b = $("#te2").val();$.post("Handler1.ashx", { "na1": a, "na2": b }, function (data) {var ser = data.split(":");if (ser == "1") {window.location.href = "HtmlPage2.html";} else {$("#h3").html("失败");}});});})</script>
</head>
<body><h3 id="h3"></h3>用户名: <input type="text" id="te1" name="name" value="" /><br />密码:<input type="password" name="name" id="te2" value="" /><br /><input type="button" name="name" id="te3" value="提交" /><br />
</body>
</html>
总结
也不知道有多少个能看到这个博客,要是能看到多几个评论吧,希望大家摒弃aspx,这种方式对服务器资源占用太多了。