扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Duane Merrill 来源:论坛整理 2007年12月24日
关键字: DB2
在本页阅读全文(共8页)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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 runat="server"> <title>DB2 AJAX Sample</title> </head> <body> <form id="form1" runat="server"> <div id="heroList"> </div> <div id="notes">Choose a Hero</div> </form> </body> </html> |
<HeaderTemplate> <h3>Available Roster:</h3> <ul class="HeroList"> </HeaderTemplate> |
<ItemTemplate> <li class="heroItem" onclick="getHeroInfo(<%# DataBinder.Eval(Container.DataItem, "HeroID")%>)" onmouseover="this.className='heroItem_hl';" onmouseout="this.className='heroItem';"> <%# DataBinder.Eval(Container.DataItem, "HeroName")%> </li> </ItemTemplate> |
<FooterTemplate> </ul> </FooterTemplate> |
<script language="javascript" type="text/javascript"> var request; function createRequest() { try { request = new XMLHttpRequest(); } catch (tryms) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (otherms) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = null; } } } if (request == null) alert("Error implementing Ajax functionality"); } function getHeroInfo(heroID) { createRequest(); var url = "http://localhost/Superpals/HeroData.asmx/getWithXML"; request.open("POST", url, true); request.onreadystatechange = showHeroInfo; request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send("heroID=" + heroID); } function showHeroInfo() { if (request.readyState == 4) { if (request.status == 200) { var xmlDoc = request.responseXML.documentElement; var notesList = xmlDoc.getElementsByTagName("HERO")[0].getElementsByTagName("NOTE"); var len = notesList.length; var notesDiv = document.getElementById("notes"); //Clear Notes Span tag while (notesDiv.firstChild) { notesDiv.removeChild(notesDiv.firstChild); } var newSpan, newText; for (var n = 0; n<len; n++) { var newSpan = document.createElement("h3"); newSpan.className = "noteTitle"; var newTextVal = notesList[n].getAttributeNode("title").nodeValue + ": "; var newText = document.createTextNode(newTextVal)newSpan.appendChild(newText); notesDiv.appendChild(newSpan); var newSpan = document.createElement("p"); newSpan.className = "noteValue"; var newTextVal = notesList[n].firstChild.nodeValue; var newText = document.createTextNode(newTextVal)newSpan.appendChild(newText); notesDiv.appendChild(newSpan); } } else { var stat = request.getResponseHeader("Status"); alert(request.status + " | " + stat); } } } </script> |
var notesList = xmlDoc.getElementsByTagName("HERO")[0].getElementsByTagName("NOTE"); |
<style type="text/css"> ul {font-family:Arial; font-size:.9em; } li { list-style:none; font-family:Arial; } h3 { font-family:Arial; font-size:1.3em} p { font-family:Arial; font-weight:normal; font-size:.9em} #notes { float:right; border-width:1px; border-style:solid; width:50%; padding:20px 20px 20px 20px;} #heroList { font-family:Arial; float:left; width:30%; padding:20px 20px 20px 20px;} .heroItem_hl { font-weight:bold; background-color:azure; } .heroItem { font-weight:normal; background-color:white; } </style> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者