XMLHttpRequest IHttpHandler
Code
1 function UserIn()
2 {
3 var user="";
4 var id="";
5 user='<%=Session["UserId"] %>';
6 id='<%=commId %>';
7 var request=new XMLHttpRequest();
8 request.open("POST", "http://www.cnblogs.com/Handler_OutIn.ashx", true);
9 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //用POST的时候一定要有这句,设置编码方式,以防乱码。
10 request.send("userId="+user+"&id="+id+"&type=in&title=&url=");
11
12 request.onreadystatechange = function()
13 {
14 if (request.readyState == 4) {
15 alert(request.responseText);
16 }
17 }
18
19 }
20
21 function UserOut()
22 {
23 if(confirm('要搬入新家吗?'))
24 {
25
26
27 var user="";
28 var id="";
29 user='<%=Session["UserId"] %>';
30 id='<%=commId %>';
31 var request=new XMLHttpRequest();
32 request.open("POST", "http://www.cnblogs.com/Handler_OutIn.ashx", true);
33 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //用POST的时候一定要有这句
34 request.send("userId="+user+"&id="+id+"&type=out&title=&url=");
35
36 request.onreadystatechange = function()
37 {
38 if (request.readyState == 4) {
39 alert(request.responseText);
40 }
41 }
42
43 }
44 }
45
46 function MyCollect()
47 {
48 var user="";
49 var title="";
50 var url="";
51 user='<%=Session["UserId"] %>';
52 title=document.title;
53 url=document.URL;
54 var request=new XMLHttpRequest();
55 request.open("POST", "http://www.cnblogs.com/Handler_OutIn.ashx", true);
56 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //用POST的时候一定要有这句
57 request.send("userId="+user+"&title="+title+"&url="+url+"&type=show&id=");
58
59 request.onreadystatechange = function()
60 {
61 if (request.readyState == 4) {
62 alert(request.responseText);
63 }
64 }
65
66
67 }
1 function UserIn()
2 {
3 var user="";
4 var id="";
5 user='<%=Session["UserId"] %>';
6 id='<%=commId %>';
7 var request=new XMLHttpRequest();
8 request.open("POST", "http://www.cnblogs.com/Handler_OutIn.ashx", true);
9 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //用POST的时候一定要有这句,设置编码方式,以防乱码。
10 request.send("userId="+user+"&id="+id+"&type=in&title=&url=");
11
12 request.onreadystatechange = function()
13 {
14 if (request.readyState == 4) {
15 alert(request.responseText);
16 }
17 }
18
19 }
20
21 function UserOut()
22 {
23 if(confirm('要搬入新家吗?'))
24 {
25
26
27 var user="";
28 var id="";
29 user='<%=Session["UserId"] %>';
30 id='<%=commId %>';
31 var request=new XMLHttpRequest();
32 request.open("POST", "http://www.cnblogs.com/Handler_OutIn.ashx", true);
33 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //用POST的时候一定要有这句
34 request.send("userId="+user+"&id="+id+"&type=out&title=&url=");
35
36 request.onreadystatechange = function()
37 {
38 if (request.readyState == 4) {
39 alert(request.responseText);
40 }
41 }
42
43 }
44 }
45
46 function MyCollect()
47 {
48 var user="";
49 var title="";
50 var url="";
51 user='<%=Session["UserId"] %>';
52 title=document.title;
53 url=document.URL;
54 var request=new XMLHttpRequest();
55 request.open("POST", "http://www.cnblogs.com/Handler_OutIn.ashx", true);
56 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //用POST的时候一定要有这句
57 request.send("userId="+user+"&title="+title+"&url="+url+"&type=show&id=");
58
59 request.onreadystatechange = function()
60 {
61 if (request.readyState == 4) {
62 alert(request.responseText);
63 }
64 }
65
66
67 }
Code
1<%@ WebHandler Language="C#" Class="Handler_OutIn" %>
2
3using System;
4using System.Web;
5using System.IO;
6public class Handler_OutIn : IHttpHandler
7{
8
9 public void ProcessRequest(HttpContext context)
10 {
11 context.Response.ContentType = "text/plain";
12 string type = "";
13 string user = "";
14 string commId = "";
15 string title = "";
16 string url = "";
17 try
18 {
19 type = context.Request["type"].ToString();
20 user = context.Request["user"].ToString();
21
22 title = context.Request["title"].ToString();
23 url = context.Request["url"].ToString();
24
25 commId = context.Request["Id"].ToString();
26
27 }
28 catch
29 {
30
31 }
32
33 if (user != null && user != "")
34 {
35 if (type == "in")
36 {
37 if (commDB.IsHasComm(user))
38 {
39 context.Response.Write("你已经入住," + user + "!");
40 }
41 else
42 {
43
44 commDB.InComm(user, commId);
45 context.Response.Write("^_^欢迎入住");
46 }
47 }
48 else if (type == "out")
49 {
50 if (commDB.IsHasComm(user) == false)
51 {
52 context.Response.Write("抱歉,你还没有入住!");
53 }
54 else
55 {
56 commDB.OutComm(user);
57 context.Response.Write("常回家看看");
58 }
59 }
60 else
61 {
62
63 userDB.AddCollect(title, url, user);
64 context.Response.Write("收藏成功");
65
66 }
67 }
68 else
69 {
70 context.Response.Write("请先登录!");
71 }
72
73 }
74 public bool IsReusable
75 {
76 get
77 {
78 return false;
79 }
80 }
81
82}
1<%@ WebHandler Language="C#" Class="Handler_OutIn" %>
2
3using System;
4using System.Web;
5using System.IO;
6public class Handler_OutIn : IHttpHandler
7{
8
9 public void ProcessRequest(HttpContext context)
10 {
11 context.Response.ContentType = "text/plain";
12 string type = "";
13 string user = "";
14 string commId = "";
15 string title = "";
16 string url = "";
17 try
18 {
19 type = context.Request["type"].ToString();
20 user = context.Request["user"].ToString();
21
22 title = context.Request["title"].ToString();
23 url = context.Request["url"].ToString();
24
25 commId = context.Request["Id"].ToString();
26
27 }
28 catch
29 {
30
31 }
32
33 if (user != null && user != "")
34 {
35 if (type == "in")
36 {
37 if (commDB.IsHasComm(user))
38 {
39 context.Response.Write("你已经入住," + user + "!");
40 }
41 else
42 {
43
44 commDB.InComm(user, commId);
45 context.Response.Write("^_^欢迎入住");
46 }
47 }
48 else if (type == "out")
49 {
50 if (commDB.IsHasComm(user) == false)
51 {
52 context.Response.Write("抱歉,你还没有入住!");
53 }
54 else
55 {
56 commDB.OutComm(user);
57 context.Response.Write("常回家看看");
58 }
59 }
60 else
61 {
62
63 userDB.AddCollect(title, url, user);
64 context.Response.Write("收藏成功");
65
66 }
67 }
68 else
69 {
70 context.Response.Write("请先登录!");
71 }
72
73 }
74 public bool IsReusable
75 {
76 get
77 {
78 return false;
79 }
80 }
81
82}
人的一生应该这样度过:当他回首往事的时候,不会因为虚度年华而悔恨,也不会因为碌碌无为而羞愧。