日期:2014-05-16  浏览次数:20461 次

ASP+AJAX+XML解决大容量表单源代码码,符注释,共享了~~
完整操作代码打包下载地址:http://download.csdn.net/source/1270171
最近因为遇到普通的AJAX提交表单,如果某个表单的内容过长就提交不了,还有表单元素过多操作也不方便,于是弄个个完整的代码,包括数据库也附上了,代码简单!

index.html
HTML code
 
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>asp+ajax+xml提交大容量,多元素表单源码 </title>
<script language=javascript>
function init(myurl,callback){
    var signatures=["Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","Msxml2.DOMDocument","Microsoft.XmlDom"];
    for(var i=0;i <signatures.length;i++)
    {
    try{var domDoc = new ActiveXObject(signatures[i]);} catch(e){ }
    }
var roots= domDoc.createElement("roots");
    var content= domDoc.createElement("content");
    content.text= document.getElementById("content").value;
    roots.appendChild(content);
var names= domDoc.createElement("names");
    names.text= document.getElementById("names").value;
    roots.appendChild(names);
    domDoc.appendChild(roots);
alert(domDoc.xml);//到这里为止,上面的代码都是操作XML
var xmlhttp;
    try{
        xmlhttp = new XMLHttpRequest();//非IE浏览器新建xmlhttp对象
    }catch(e){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器新建xmlhttp对象
    }
xmlhttp.onreadystatechange = function(){
        if(4 == xmlhttp.readyState){
            if(200 == xmlhttp.status){
                var date = xmlhttp.responseText;//得到a.asp的网页内容,这句可以要可以不要
callback(xmlhttp);//这里是调用info()这个函数
            }else{
                alert("冒似有错");
            }
        }
    }
xmlhttp.open("POST",myurl,true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send (domDoc);//发送domDoc到a.asp
}
function info(){
alert("成功了完成提交");
}
</script>
</head>
<body>
<textarea id="content" name="content" cols="60" rows="10"> </textarea> <br>
<input id="names" type="text" value="" />
<input name="" type="button" onClick="init('a.asp',info)" value=" 提 交 ">
</body>
</html>


a.asp
VBScript code
<!--#include file="conn.asp" -->
<%
Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")'新建xmldoc对象
xmlDoc.Async=False '这里是同步的意思,async是异步的意思,async=false就是同步了
xmlDoc.load request'获取index.html传过来的XML文档
Set content = xmlDoc.selectSingleNode("/roots/content")'取content节点
Set names = xmlDoc.selectSingleNode("/roots/names")'取names节点
sql = "select * from [users]"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.