js 局部刷新數據庫數據

js code:

<script type="text/javascript">
//<![CDATA[
    function fLoadXml(url, show){
    
//var drp1 = document.getElementById("TextBox1");
    var ClassID="1";//drp1.options[drp1.selectedIndex].value;
    
    
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
  
var oDoc = new ActiveXObject("microsoft.xmldom");
  oHttpReq.open(
"POST""data.aspx?ClassID="+ClassID, false); 
  
//
  //调用读取小类数据的页面,将大类
  // 编号值传递过去
  oHttpReq.send("");
  
//result = oHttpReq.responseText;
  
        
switch(fCkDom2()){
            
case 1:
                
var xml=document.implementation.createDocument('','',null);
                    xml.onload 
= function(){show(xml, url);}
                    xml.load(url);
                
break;
            
case 2
                
var xml=new ActiveXObject('microsoft.xmldom');
                    xml.onreadystatechange
=function(){
                        
if(xml.readyState==4){
                            show(xml, url);
                        }

                    }
 
                    xml.load(url);
                
break;
            
default: document.write('unknown');
        }

        
        
function fCkDom2(){
            
if(document.implementation&&document.implementation.createDocument)return 1;
            
else if(window.ActiveXObject) return 2;
            
else return 0;
        }

    }

    
    
function fShowXml(xml, url){
  
// var drp2 = document.getElementById("TextBox1");
    //alert(drp2);
 
        
//alert('ok');
        var elements=xml.getElementsByTagName('Table');
            
for(var i=0; i<elements.length; i++){
                
                
for(var j=0; j<elements[i].childNodes.length; j++){
                    
if(elements[i].childNodes[j].nodeType==1){
                        
var eSub=elements[i].childNodes[j]
                    
                        
var content;
            
                            
try{
                                content
=eSub.firstChild.data;//.fontcolor('blue');
                            }
 catch(e){
                                content
='empty';
                            }

                    
                    
//将小类的类名和编号赋予DropDownList2
                 
                     
//var newOption = document.createElement("OPTION");
                     // newOption.text=content;
                     
                      
//newOption.value=content;
                      
                      
//drp2.options.add(newOption);
                      //alert(content);
                      DIV1.innerHTML =content;
                    }

                }
  
            }

    }

//]]>onload="fLoadXml('xml.xml', fShowXml);"onload="fLoadXml('xml.xml', fShowXml);"
        </script>
        
<script language="javascript">
function getMessage()

//window.alert("ok!");
//
var timer=setInterval("fLoadXml('xml.xml', fShowXml);",2000)
//
window.setTimeout("opencontent()", 5000);
//
window.setTimeout("fLoadXml('xml.xml', fShowXml);",1000);//1秒钟后执行,且只执行一次
//
window.setInterval("fLoadXml('xml.xml', fShowXml);",10000);//不停的执行,每隔5秒
//
window.onload =getMessage();//onload="getMessage()"
{
window.alert(
"ok!");
fLoadXml(
"xml.xml", fShowXml);
}

//var timer=setTimeout("getMessage()",2000)
window.setInterval("getMessage()",10000);

        
</script>

調用:
其中fLoadXml("xml.xml", fShowXml) xml.xml是一個xml的文檔

<body onload="getMessage()">
DIV1是一個div的id
data.aspx
private void Page_Load(object sender, System.EventArgs e)
  {
   // Put user code to initialize the page here
    
      SqlConnection   con   =   new   SqlConnection("server=(local);uid=sa;pwd=breakin;database=E_Quotation");  
      SqlDataAdapter   da   =   new   SqlDataAdapter("select name from t where pid='007'",con);  
      DataSet   ds   =   new   DataSet();  
      da.Fill(ds);  
    ds.WriteXml(Server.MapPath("xml.xml"));
  }



 

posted @ 2007-01-05 11:16  Nina  阅读(1429)  评论(1编辑  收藏  举报