<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
function ajaxEx() {
alert("hello");
var name = document.insertForm.T_name.value;
alert(name);
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
var url ="searchAction?T_name="name;
xmlHttp.open("post",url,true);
xmlHttp.onreadystatechange=function (){
if(xmlHttp.readystate == 4){
resultDiv.innerHTML +=xmlHttp.responseText;
}
else{
alert("hello");
}
}
xmlHttp.send();
}
</script>
<form method="post" name="insertForm" style="margin-bottom: 50px;margin-top: 50px;">
請輸入要查詢的圖書的信息:<br/>
<br /> 名稱:<input type="text" name="T_name" onkeyup="ajaxEx()">
</form>
<hr>
書籍信息<br>
<ul style="height: 0px ;padding: 0px;margin: 0px;">
<li style="width: 80px;display: inline-block;list-style: none;">名稱</li>
<li style="width: 40px;display: inline-block;list-style: none;">編號</li>
<li style="width: 40px;display: inline-block;list-style: none;">價格</li>
</ul><br/>
<div id="resultDiv">
</div>
</body>
</html>
# 去掉這部分之後,js就可以彈出了“hello”
xmlHttp.open("post",url,true);
xmlHttp.onreadystatechange=function (){
if(xmlHttp.readystate == 4){
resultDiv.innerHTML +=xmlHttp.responseText;
}
else{
alert("hello");
}
}
xmlHttp.send();
var url ="searchAction?T_name="name;
==>>
var url ="searchAction?T_name="+name;