OLD | NEW |
(Empty) | |
| 1 <%@ page import="java.util.*" %> |
| 2 <%@ page import="java.net.*" %> |
| 3 <%@ page import="java.io.*" %> |
| 4 |
| 5 <HTML> |
| 6 <HEAD> |
| 7 <TITLE> |
| 8 AJAX DEMO : Getting JavaReference Author Profile using Ajax interaction |
| 9 </TITLE> |
| 10 </HEAD> |
| 11 |
| 12 |
| 13 <script type="text/javascript"> |
| 14 var httpRequest; |
| 15 |
| 16 /** |
| 17 * This method is called when the author is selected |
| 18 * It creates XMLHttpRequest object to communicate with the |
| 19 * servlet |
| 20 */ |
| 21 function getProfile() |
| 22 { |
| 23 var url = 'http://build.chromium.org/buildbot/perf/dashboard/ui/changelo
g.html?url=/branches/249/src&range=42898:44010&mode=html'; |
| 24 |
| 25 if (window.ActiveXObject) |
| 26 { |
| 27 httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); |
| 28 } |
| 29 else if (window.XMLHttpRequest) |
| 30 { |
| 31 httpRequest = new XMLHttpRequest(); |
| 32 } |
| 33 |
| 34 httpRequest.open("GET", url, true); |
| 35 httpRequest.onreadystatechange = function() {processRequest(); } ; |
| 36 httpRequest.send(null); |
| 37 } |
| 38 |
| 39 /** |
| 40 * This is the call back method |
| 41 * If the call is completed when the readyState is 4 |
| 42 * and if the HTTP is successfull when the status is 200 |
| 43 * update the profileSection DIV |
| 44 */ |
| 45 function processRequest() |
| 46 { |
| 47 if (httpRequest.readyState == 4) |
| 48 { |
| 49 if(httpRequest.status == 200) |
| 50 { |
| 51 //get the XML send by the servlet |
| 52 var profileXML = httpRequest.responseXML.getElementsByTagName("p
re")[0]; |
| 53 |
| 54 //Update the HTML |
| 55 updateHTML(profileXML); |
| 56 } |
| 57 else |
| 58 { |
| 59 alert("Error loading page\n"+ httpRequest.status +":"+ httpReque
st.statusText); |
| 60 } |
| 61 } |
| 62 } |
| 63 |
| 64 /** |
| 65 * This function parses the XML and updates the |
| 66 * HTML DOM by creating a new text node is not present |
| 67 * or replacing the existing text node. |
| 68 */ |
| 69 function updateHTML(profileXML) |
| 70 { |
| 71 //The node valuse will give actual data |
| 72 var profileText = profileXML.childNodes[0].nodeValue; |
| 73 |
| 74 //Create the Text Node with the data received |
| 75 var profileBody = document.createTextNode(profileText); |
| 76 |
| 77 //Get the reference of the DIV in the HTML DOM by passing the ID |
| 78 var profileSection = document.getElementById("profileSection"); |
| 79 |
| 80 //Check if the TextNode already exist |
| 81 if(profileSection.childNodes[0]) |
| 82 { |
| 83 //If yes then replace the existing node with the new one |
| 84 profileSection.replaceChild(profileBody, profileSection.childNodes[0
]); |
| 85 } |
| 86 else |
| 87 { |
| 88 //If not then append the new Text node |
| 89 profileSection.appendChild(profileBody); |
| 90 } |
| 91 } |
| 92 |
| 93 </script> |
| 94 |
| 95 <BODY> |
| 96 |
| 97 <TABLE align=left border=0 cellPadding=3 cellSpacing=1 width="100%" > |
| 98 <TR> |
| 99 <TD align="center"> |
| 100 <STRONG>Getting JavaReference Author Profile using Ajax interaction.
</STRONG> |
| 101 <br> |
| 102 </TD> |
| 103 </TR> |
| 104 |
| 105 <TR bgColor="#FFD0B1"> |
| 106 <TD> |
| 107 <div id="profileSection"> |
| 108 <br><br> |
| 109 <div> |
| 110 |
| 111 <script type="text/javascript"> |
| 112 getProfile(); |
| 113 </script> |
| 114 |
| 115 </TD> |
| 116 </TR> |
| 117 </TABLE> |
| 118 |
| 119 </BODY> |
| 120 </HTML> |
OLD | NEW |