1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="pack.AcceBase"%>
<%@page import="java.sql.ResultSet"%><html>
<script type="text/javascript">
<!--
function getXMLHttpRequest() {
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhr = new XMLHttpRequest();
}
} else {
alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
return null;
}
return xhr;
}
function request(id) {
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
readData(xhr.responseXML);
};
xhr.open("GET", "test.jsp?id="+id, true);
xhr.send("null");
}
function readData(oData) {
var nodes = oData.getElementsByTagName("item");
var oSelect = document.getElementById("moi");
var oOption, oInner;
oSelect.innerHTML = "";
for (var i=0, c=nodes.length; i<c; i++) {
oInner = document.createTextNode(nodes[i].getAttribute("id"));
oOption.appendChild(oInner);
}
}
//-->
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ajax</title>
</head>
<body>
<table>
<tr>
<td>Auteur</td>
<td>Livres</td>
</tr>
<tr>
<td>
<%
AcceBase acc=new AcceBase();
String re="select * from auteur";
ResultSet r= acc.SelectRequete(re);
while(r.next())
{
out.print("<a href='request("+r.getInt("id")+")'>"+r.getString("nom")+"</a><br>");
}
%>
</td>
</tr>
</table>
<div id="moi"></div>
</body>
</html> |
Partager