index.asp
----------------------------------------------------------
<script src="ajax.js></script>
<form>
</ul>
<li>Q Q:<input type="text" maxlength="10" id="qq" /></li>
<li>性别:<input type="radio" name="sex" value="BOY" checked="checked"/>男<input type="radio" name="sex" value="GIRL"/>女<input type="radio" name="sex" value="NONE"/>保密</li>
<li>留言:<textarea id="content" cols="60" rows="10"></textarea></li>
<input type="button" onclick="sendJS();" value="保存" class="button" id="submit" />
</ul>
</form>
----------------------------------------------------------以上提交用sendJS()处理
ajax.js
function sendJS(){
xmlHttp = XMLHttpRequest();
var qq,sex,content,url;
qq = getVal("qq");
sex = getVal("sex");
content = getVal("content");
url="";
if(xmlHttp){
url ="save.asp?qq="+escape(qq)+"&sex="+escape(sex)+"&content="+escape(content);
xmlHttp.open("get",url,true);
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readystate==4){
if(xmlHttp.status==200){
if(xmlHttp.responseText=="1"){
alert("添加成功!");
}else if(xmlHttp.responseText=="0"){
alert("填写完整!")
}//1
}else{
alert("网络错误");
}//200
addMessage();
}//4
};//xmlhttp.onready
xmlHttp.send(null);
}//if xmlhttp
}//fun
function XMLHttpRequest(){
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttp != 'undefined')
xmlHttp = new XMLHttpRequest();
return xmlHttp;
}
数据的处理交给了save.asp
----------------------------------------------------------
<!--#include file="conn.asp"-->
<%
dim qq,sex,content
qq = request.QueryString("qq")
sex = request.QueryString("sex")
content = request.QueryString("content")
response.Write(content)
dim rs
set rs = server.createobject("adodb.recordset")
rs.Open "book",conn,3,3
if qq="" or content="" then
Response.Write("0")
else
rs.AddNew
rs("qq")=qq
rs("sex")=sex
rs("content")=content
rs.Update
rs.Close
set rs=nothing
Response.Write("1")
end if
%>
以上是保存到数据库,看下篇的读取数据库