Active Server Pages

Moderators: None (Apply to moderate this forum)
Number of threads: 1763
Number of posts: 4498

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
This is split between AJAX and ASP but should go here... Posted by aaronjones3593 on 9 Mar 2007 at 2:00 AM
This message was edited by aaronjones3593 at 2007-3-9 2:1:24

I'm making a web chat application and I'm a bit stumped on something. It uses a database to keep track of who's online, and I have an AJAX form thing that gets the contact list from list.asp every 5 seconds; like so...

main.asp
<!-- CONTACT LIST SECTION -->
<div id="ContactList" style="position:absolute; top:10px; left:10px">
  <img src="./img/list.loading.gif" border="0" style="position:relative;top:3px;left:55px">
  <p style="position:relative;top:3px;left:5px">Loading the contact list...</p>
</div>

<script language="JavaScript">
var AJAXObject = null;
try { AJAXObject = new XMLHttpRequest(); } catch (e) { /* Not using Firefox, Safari or Opera */ }
try { AJAXObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { /* Not using Internet Explorer */ }

var Timer = 2000;

function GetContactList()
{
 document.getElementById("SendFormSeperator").style.display = "none";
 document.getElementById("SendTextForm").style.display = "none";
 if (AJAXObject != null)
 {
  var LoginHandle = "<%=Session("LoginHandle")%>"
  AJAXObject.onreadystatechange = stateChanged();
  AJAXObject.open("GET", "./list.asp?sid=" + Math.random() + "&LoginHandle=" + LoginHandle, true);
  AJAXObject.send(null);
  
  window.setTimeout("GetContactList()", Timer);
  Timer = 5000
 }
  else
 {
  alert("Your browser does NOT support AJAX!")
 }
}

function stateChanged() 
{ 
 if (AJAXObject.readyState == 4)
 {
  var ResponseText = AJAXObject.responseText;
  document.getElementById("ContactList").innerHTML = ResponseText;
  if (ResponseText.indexOf("No online users") == -1)
  {
   document.getElementById("SendFormSeperator").style.display = "";
   document.getElementById("SendTextForm").style.display = "";
  }
 }
}
</script>


list.asp
<table cellspacing="3" cellpadding="1" border="0" width="120">
<%
  Dim adoCon
  Dim Recordset
  Dim strSQL
  
  Set adoCon = Server.CreateObject("ADODB.Connection")
  Set Recordset = Server.CreateObject("ADODB.Recordset")

  adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("./db/users.mdb")
  
  strSQL = "SELECT UserID,CurrentStatus,DisplayName FROM WCAUsers WHERE CurrentStatus <> 'offline'"
  strSQL = strSQL & " AND LoginHandle <> '" & Request.QueryString("LoginHandle") & "'"
  Recordset.Open strSQL, adoCon
  
  IF Recordset.EOF Then
    Response.Write "<tr><td>No online users</td></tr>"
  End If

  Do While Not Recordset.EOF
	Response.Write "<tr><td valign='top' onclick='OpenConvo(" & Recordset("UserID") & ")'>" & _
	               "<img src='./img/" & Recordset("CurrentStatus") & ".png'>&nbsp;" & _
	               Recordset("DisplayName") & "</td></tr>"
	Recordset.MoveNext
  Loop
	
  Recordset.Close
  Set Recordset = Nothing
  adoCon.Close
  Set adoCon = Nothing
%>
</table>


as you can see in list.asp it gets the users where their status is not offline... but some people just close the window without signing out first. I don't want something that will tell them to sign out first when they click the X button ot anything; I want something that I can do in AJAX/ASP to check on the client say like every 30 seconds or so... and if there is no response (closed the window, anyone?) then force sign them out (update database status to offline).

I'm a bit stuck on thinking how I could do/implement this... any ideas?

Thanks in advance,




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.