一段AJAX代码

<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%
  	String mailUrl = "http://****/mailmanager.nsf/OpenMail?OpenAgent";
	String mailListUrl = "http://***mailmanager.nsf/MailPicker.xml?OpenAgent&count=5&unread=1"; 
%>
<script language="javascript">
function createRequestObject() {
	 var xmlhttp;
	 try {
	    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	  usewin = "msxml";
	 }
	 catch(e) {
	  try {
	      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	   usewin = "microsoft";
	  }
	  catch(e) {
	      xmlhttp=null;
	  }
	 }
	
	 if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	  
	    xmlhttp=new XMLHttpRequest();
	    usewin = "undefined";
	 }
	 return  xmlhttp;
}

function handleResponseEmail() {
	

  if((http.readyState == 4)&&(http.status == 200)){
	   var response = http.responseXML.documentElement;
	   var node;
	   node = response.getElementsByTagName('mail');
	   var s="";
	   var c="";
	   var t="";
	   var m="";
	   var mailNum = response.getElementsByTagName('new_mail').item(0).firstChild.nodeValue;
   
	   for(var i=0;i<node.length;i++){  
	   	 m="";
	   	  var table=document.all("mail");
	      var rows=table.rows;
	      var rowcount=rows.length;
	      var centrow=table.insertRow(rowcount);
	      var cells=centrow.cells;
	      var cell0=rows(centrow.rowIndex).insertCell(cells.length);
	      cell0.background="/wps/PA_w9j7ju3/images/nw-right-de.gif";
		  
	   	   	m="<table width=\"100%\" background=\"/wps/PA_w9j7ju3/images/nw-right-de.gif\"><tr>"+
			  "<td> <img border=\"0\" src=\"/wps/PA_w9j7ju3/images/arrow.gif\" width=\"3\" height=\"5\"><a target=\"_blank\"";
		  	 m+="href=\""+ node.item(i).getElementsByTagName('url').item(0).firstChild.nodeValue;
		  	 m +="\" title=\""+node.item(i).getElementsByTagName('title').item(0).firstChild.nodeValue;
		   	m +="  " + node.item(i).getElementsByTagName('from').item(0).firstChild.nodeValue;
			m+= "\"> ";
			c = node.item(i).getElementsByTagName('title').item(0).firstChild.nodeValue;
			 if(c.length >10 ) c = c.substr(0,10)+"...";
			 m+=c;
			 m+="</a>";
			m+= "</td><td align=\"right\">";
			 t = node.item(i).getElementsByTagName('receive_time').item(0).firstChild.nodeValue;
	         t = t.substr(0,t.lastIndexOf(":"));
	         m+=t;
	        m+="</td></tr></table>"	;
	     
	   	  cell0.innerHTML=m;
	   	  
	   	 
	   	  	  var table=document.all("mail");
		      var rows=table.rows;
		     var  rowcount=rows.length;
		     var  centrow=table.insertRow(rowcount);
		     var  cells=centrow.cells;
		      var cell0=rows(centrow.rowIndex).insertCell(cells.length);
	     cell0.background="images/nw-right-de.gif";
		   	  var	l="";
		   	  l="<img border=\"0\" src=\"/wps/PA_w9j7ju3/images/nw-right-line.gif\" width=\"261\"height=\"1\">"; 
		   	  cell0.innerHTML=l;
			
			 
	   }
	 	 var table=document.all("mail");
	     var rows=table.rows;
	     var  rowcount=rows.length;
	     var  centrow=table.insertRow(rowcount);
	     var  cells=centrow.cells;
	     var cell0=rows(centrow.rowIndex).insertCell(cells.length);
	  	 var	l2="";
	  	 l2="<img border=\"0\" src=\"/wps/PA_w9j7ju3/images/nw-right-line0.gif\" width=\"261\"height=\"1\">"; 
	  	 cell0.innerHTML=l2;
  }
 
}


function sendRequest(xmlurl) {
	
  
  http = createRequestObject();
  
  http.open("GET", xmlurl, true);
  http.setRequestHeader('Content-Type',"text/xml");
  http.onreadystatechange = handleResponseEmail;
  http.send(null);
 }
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<STYLE type="text/css">
		A:link {
			COLOR: #0440AF; TEXT-DECORATION: none
		}
		A:visited {
			COLOR: 014498; TEXT-DECORATION: none
		}
		A:active {
			COLOR: #014BC5
		}
		A:hover {
			COLOR:E9730B; TEXT-DECORATION: none
		}
		TD {
			COLOR: #0440AF; FONT-FAMILY: 宋体; FONT-SIZE: 9pt
		}
	</STYLE>
</head>
<body>
<form method="post" name="frm">

<table border="0" width="261" cellspacing="0" cellpadding="0" id="mail">
			<tr>
				<td width="100%" height="10"></td>
			</tr>
			<tr>
				<td width="261" background='/wps/PA_w9j7ju3/images/nw-right-jryl.gif' height="42">
					<table border="0" width="100%" height="42" cellspacing="0"
						cellpadding="0">
						<tr>
							<td width="50%">
								       
								<b>办公邮件</b>
							</td>
							<td width="50%">
								               
								<a target="_blank"
									href="<%=mailUrl %>">
									<img border="0" src="/wps/PA_w9j7ju3/images/nw-left-more.gif" width="25"
										 height="5">
								</a>	
							</td>
						</tr>
					</table>
				</td>
			</tr>
				
				
					
			
</table>

</form>
</body>
</html>
<script type="text/javascript">

   sendRequest("a.xml");
</script>
a.xml

 

<?xml version="1.0" encoding="gb2312" ?><response>
<result type="0">
<message></message></result>
<new_mail><![CDATA[61]]></new_mail>
<mail_list>

<mail>
<title><![CDATA[***应用推进月度检查评分小结]]></title>
<from><![CDATA[符**]]></from>
<receive_time><![CDATA[2008-09-01 17:02:31]]></receive_time>
<priority><![CDATA[2]]></priority>
<read_flag><![CDATA[0]]></read_flag>
<attachment_flag><![CDATA[2]]></attachment_flag>
<url><![CDATA[http://**.nsf/NewWebMail?]]></url>
</mail>
<mail>
<title><![CDATA[测试短信通知]]></title>
<from><![CDATA[***]]></from>
<receive_time><![CDATA[2008-08-29 10:23:45]]></receive_time>
<priority><![CDATA[2]]></priority>
<read_flag><![CDATA[0]]></read_flag>
<attachment_flag><![CDATA[0]]></attachment_flag>
<url><![CDATA[http://***/NewWebMail?]]></url>
</mail>

</mail_list>
</response>

 

你可能感兴趣的:(JavaScript,C++,c,Ajax,C#)