那是我的代码:
<input type="button" id="SignOut" value="SignOut" onclick="logout();" />
服务器端:
public void ondisconnected() // when the user is disconnected
{
try
{
DataRow[] UserRow = ConnectedClientDt.Select("ConnectionID='" + Context.ConnectionId + "'");
int ClientID = Convert.ToInt32(UserRow[0][0]);
new SQLHelper(SQLHelper.ConnectionStrings.WebSiteConnectionString).Update("Update clients set USER_STATUS='F' where CLIENT_ID=" + ClientID);
string query = " Select FRIEND_ID from friends where CLIENT_ID= " + ClientID;
DataTable FriendsDt = new SQLHelper(SQLHelper.ConnectionStrings.WebSiteConnectionString).getQueryResult(query);
for (int i = 0; i < FriendsDt.Rows.Count; i++)
{
DataRow[] FrRow = ConnectedClientDt.Select("ClientId=" + FriendsDt.Rows[i][0] + "");
if (FrRow.Length > 0)
Clients.Client(FrRow[0][2].ToString()).userDisconnected(ClientID);
}
DeleteUser(Context.ConnectionId);
}
catch (Exception ex)
{
return ;
}
}
客户端:
function logout() {
$.connection.chatHub.server.ondisconnected();
setTimeout(window.location= "LoginPage.aspx?action=logout", 5000);
}
当我按下按钮时,ondisconnected 函数没有执行,但是当我删除 settimeout 行时,代码正常工作,没有任何问题:s