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