用XMLHTTP实现简单聊天功能的程序---讨论就有分
用XMLHTTP实现最简单的聊天程序
=======================================================
default.asp
<head>
<style>
td,body,a{font-size:9pt;color:#000000;text-decoration:none}
</style>
<script language=javascript>
function ref()
{
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.open("POST","ref.asp",false);
xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
xmlhttp.send();
txt.document.write(xmlhttp.responseText);
}
setInterval("ref();",1);
</script>
</head>
<body leftmargin=0 topmargin=0 rightmargin=0>
<iframe name=txt width=700 height=400 frameborder=0></iframe>
</body>
======================================================================
ref.asp
<!--#include file=conn.asp-->
<%
if session("chat_id")="" then session("chat_id")=0
rs.open "select id,ifrom,ito,txt from chat where id>" & session("chat_id") & " order by
id",conn,1,1
do while not rs.eof
response.write rs("ifrom") & "对" & rs("ito") & "说:" & rs("txt")
session("chat_id")=rs("id")
rs.movenext
loop
rs.close
%>
其中,id是聊天记录的自动编号,ifrom是发送者姓名,ito是接受者姓名,txt是聊天记录内容
=============================================================
调试后,页面没反映,此时数据库中已经存入3条记录了,id分别是1、2、3
以上两个页面一定存在不少问题,我刚刚接触XMLHTTP,它的用法我不怎么了解,希望大家一起讨论讨论