这几天瞎弄一个Ajax+asp的聊天程序,还是一个菜鸟不要见怪。Ajax技术主要是为了实现无刷新更新内容和提交。
分别提交“乱码”和“乱码啊”显示结果如下:
- Angel
- 2009-7-26 9:37:36
- 乱码
- Angel
- 2009-7-26 9:37:29
- 乱码�/li>
问题就是它把“乱码啊” 显示为“乱码�/li>”打开数据库显示的也是乱码“涔辩爜”和“涔辩爜鍟”。数据库wwwlink.mdb 结构一个link表,字段link_id,name,intro,submit_date,
conment表,字段ID,user,Password 哪位虾仁能有好的解决方法。
源文件 1.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body onload="ajaxFunction();">
<script type="text/javascript" src ="ajax.js">
</script>
<div id="txtHint"></div>
<form>
<textarea id="intro" cols="40" name="intro" rows="6" ></textarea>
<input type="button" id="submit" value="确定" name="B1" onclick ="getFunction();">
<div id ="anme"></div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body onload="ajaxFunction();">
<script type="text/javascript" src ="ajax.js">
</script>
<div id="txtHint"></div>
<form>
<textarea id="intro" cols="40" name="intro" rows="6" ></textarea>
<input type="button" id="submit" value="确定" name="B1" onclick ="getFunction();">
<div id ="anme"></div>
</form>
</body>
</html>
ajax.js源代码
function XmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function ajaxFunction() {
var xmlHttp = XmlHttpObject();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("POST", "msg.asp", true);
xmlHttp.send(null);
window.setTimeout("Repeat()", 100);
}
function Repeat()
{
window.setTimeout("ajaxFunction()", 100);
}
function GE(a){return document.getElementById(a);}
function getFunction() {
var xmlHttp = XmlHttpObject();
xmlHttp.open('post', 'ada.asp', true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var SendData = 'intro=' + GE('intro').value;
xmlHttp.send(SendData)
GE('intro').value=""
}
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function ajaxFunction() {
var xmlHttp = XmlHttpObject();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("POST", "msg.asp", true);
xmlHttp.send(null);
window.setTimeout("Repeat()", 100);
}
function Repeat()
{
window.setTimeout("ajaxFunction()", 100);
}
function GE(a){return document.getElementById(a);}
function getFunction() {
var xmlHttp = XmlHttpObject();
xmlHttp.open('post', 'ada.asp', true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var SendData = 'intro=' + GE('intro').value;
xmlHttp.send(SendData)
GE('intro').value=""
}
msg.asp源代码
<!-- #include file="conn.asp" -->
<%
dim a
a=0
Do While Not rs.Eof and a<5
%>
<div id="msg">
<ul>
<li><%=rs("Name")%></li>
<li><%=rs("submit_date")%></li>
<li><%=rs("intro")%></li>
</ul>
</div>
<%
rs.MoveNext
a=a+1
Loop
%>
<%
dim a
a=0
Do While Not rs.Eof and a<5
%>
<div id="msg">
<ul>
<li><%=rs("Name")%></li>
<li><%=rs("submit_date")%></li>
<li><%=rs("intro")%></li>
</ul>
</div>
<%
rs.MoveNext
a=a+1
Loop
%>
ada.asp源代码
<% Option Explicit %>
<!-- #include file="conn.asp" -->
<%
Dim varName,varURL,varIntro
varName=Session("name")
varIntro=Request.Form("intro")
if varIntro<>"" then
StrSql="Insert Into link(name,intro,submit_date) Values('" & varName & "','" & varIntro & "',#" & now() & "#)"
db.Execute(strSql)
end if
%>
<!-- #include file="conn.asp" -->
<%
Dim varName,varURL,varIntro
varName=Session("name")
varIntro=Request.Form("intro")
if varIntro<>"" then
StrSql="Insert Into link(name,intro,submit_date) Values('" & varName & "','" & varIntro & "',#" & now() & "#)"
db.Execute(strSql)
end if
%>