紧急求助——添加朋友功能在开发测试系统运行无误,放到服务上,添加朋友老是提示失败,参数也能看到传递。
三个主要页面代码如下:
1.搜索页首页index添加好友代码如下:
protected string AddFriend(object uid, object unm)
{
string ret = string.Empty;
string upic = GetHeadImage(Convert.ToInt32(uid.ToString()), 2);
if (isTimeOut())
{
ret = "<div id=\"li_req_" + uid.ToString() + "\"><a href=\"javascript:void(0);\" onclick=\"javascript:AddFriend(" + uid.ToString() + ",'" + unm.ToString() + "','" + upic.ToString() + "','li_req_" + uid.ToString() + "');\">加为好友</a></div>";
}
else
{
int usid = Convert.ToInt32(uid);
Friend frd = new Friend();
if (usid != this.GetUserID())
{
int n = frd.GetRelation(this.GetUserID(), usid);
if (n == 0)//无任何关系
{
ret = "<div id=\"li_req_" + usid + "\"><a href=\"javascript:void(0);\" onclick=\"javascript:AddFriend(" + usid + ",'" + unm + "','" + upic + "','li_req_" + uid + "');\">加为好友</a></div>";
}
else if (n == 3)//已发出好友申请,等待确认好友申请
{
ret = "<div>等待验证</div>";
}
else if (n == 4)//4被申请
{
ret = "<div><a href=\"../friend/req.aspx\">处理请求</a></div>";
}
}
}
return ret;
}
2。调用friend.js中代码文件//加为好友
function AddFriend(uid,uname,upic,objid)
{
ShowDlg(464,220,'将'+ uname +'加为好友?','<div class=\"nl w100\"><img src="'+ upic +'" alt="'+ uname +'" align="absmiddle" /></div><div class=\"nr w300 paddings10\">你的请求会发送给'+ uname +',确认后你们将成为好友。</div>','OnAddFriend('+ uid +',\''+ objid +'\')');
}
function OnAddFriend(uid,objid)
{
var options={
method:'post',
parameters:'Option=ApplyFrd&FriendID='+ uid,
onComplete:
function(transport)
{
var retv =transport.responseText;
if(retv == '1')
{
document.getElementById(objid).innerHTML = '等待验证';
}
else if(retv == 'err')
{
alert("请登录后进行操作");
}
else
{
alert("添加朋友失败");
}
HideAlertBox();
}
}
new Ajax.Request(RootDir+'/inc/ajax/friend/friendAjax.aspx',options);
}
3. friend.js调用ajax代码friendAjax.aspx如下 protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
//{
if (this.GetUserID() == 0)
{
Response.Write("err");
Response.End();
}
if (Request.Form["Option"] != null)
{
JuSNS.Home.Friend fnd = new JuSNS.Home.Friend();
string opt = Request.Form["Option"];
try
{
switch (opt)
{
case "Greet":
fnd.Greet(this.GetUserID(), int.Parse(Request.Form["FriendID"]));
Response.Write("1");
//&FriendID="+ uid,
break;
case "Delete":
fnd.Diffidation(this.GetUserID(), int.Parse(Request.Form["FriendID"]));
Response.Write("1");
//&FriendID="+ uid,
break;
case "ApplyFrd":
fnd.Request(this.GetUserID(), int.Parse(Request.Form["FriendID"]));
Response.Write("1");
break;
case "Accept":
fnd.Response(this.GetUserID(), int.Parse(Request.Form["RID"]), EnumReply.Agree, Request.Form["ClassID"]);
Response.Write("1");
break;
case "Refuse":
fnd.Response(this.GetUserID(), int.Parse(Request.Form["RID"]), EnumReply.Decline, string.Empty);
Response.Write("1");
break;
}
}
catch
{
Response.Write("0");
}
}
Response.End();
}
三个主要页面代码如下:
1.搜索页首页index添加好友代码如下:
protected string AddFriend(object uid, object unm)
{
string ret = string.Empty;
string upic = GetHeadImage(Convert.ToInt32(uid.ToString()), 2);
if (isTimeOut())
{
ret = "<div id=\"li_req_" + uid.ToString() + "\"><a href=\"javascript:void(0);\" onclick=\"javascript:AddFriend(" + uid.ToString() + ",'" + unm.ToString() + "','" + upic.ToString() + "','li_req_" + uid.ToString() + "');\">加为好友</a></div>";
}
else
{
int usid = Convert.ToInt32(uid);
Friend frd = new Friend();
if (usid != this.GetUserID())
{
int n = frd.GetRelation(this.GetUserID(), usid);
if (n == 0)//无任何关系
{
ret = "<div id=\"li_req_" + usid + "\"><a href=\"javascript:void(0);\" onclick=\"javascript:AddFriend(" + usid + ",'" + unm + "','" + upic + "','li_req_" + uid + "');\">加为好友</a></div>";
}
else if (n == 3)//已发出好友申请,等待确认好友申请
{
ret = "<div>等待验证</div>";
}
else if (n == 4)//4被申请
{
ret = "<div><a href=\"../friend/req.aspx\">处理请求</a></div>";
}
}
}
return ret;
}
2。调用friend.js中代码文件//加为好友
function AddFriend(uid,uname,upic,objid)
{
ShowDlg(464,220,'将'+ uname +'加为好友?','<div class=\"nl w100\"><img src="'+ upic +'" alt="'+ uname +'" align="absmiddle" /></div><div class=\"nr w300 paddings10\">你的请求会发送给'+ uname +',确认后你们将成为好友。</div>','OnAddFriend('+ uid +',\''+ objid +'\')');
}
function OnAddFriend(uid,objid)
{
var options={
method:'post',
parameters:'Option=ApplyFrd&FriendID='+ uid,
onComplete:
function(transport)
{
var retv =transport.responseText;
if(retv == '1')
{
document.getElementById(objid).innerHTML = '等待验证';
}
else if(retv == 'err')
{
alert("请登录后进行操作");
}
else
{
alert("添加朋友失败");
}
HideAlertBox();
}
}
new Ajax.Request(RootDir+'/inc/ajax/friend/friendAjax.aspx',options);
}
3. friend.js调用ajax代码friendAjax.aspx如下 protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
//{
if (this.GetUserID() == 0)
{
Response.Write("err");
Response.End();
}
if (Request.Form["Option"] != null)
{
JuSNS.Home.Friend fnd = new JuSNS.Home.Friend();
string opt = Request.Form["Option"];
try
{
switch (opt)
{
case "Greet":
fnd.Greet(this.GetUserID(), int.Parse(Request.Form["FriendID"]));
Response.Write("1");
//&FriendID="+ uid,
break;
case "Delete":
fnd.Diffidation(this.GetUserID(), int.Parse(Request.Form["FriendID"]));
Response.Write("1");
//&FriendID="+ uid,
break;
case "ApplyFrd":
fnd.Request(this.GetUserID(), int.Parse(Request.Form["FriendID"]));
Response.Write("1");
break;
case "Accept":
fnd.Response(this.GetUserID(), int.Parse(Request.Form["RID"]), EnumReply.Agree, Request.Form["ClassID"]);
Response.Write("1");
break;
case "Refuse":
fnd.Response(this.GetUserID(), int.Parse(Request.Form["RID"]), EnumReply.Decline, string.Empty);
Response.Write("1");
break;
}
}
catch
{
Response.Write("0");
}
}
Response.End();
}
我也看晕了,楼主,将具体哪个地方出错了,说下