81,092
社区成员
发帖
与我相关
我的任务
分享
var http = getHTTPObject();
var divIsOpen = false;
//该函数可以创建我们需要的XMLHttpRequest对象
function getHTTPObject() {
var xmlhttp = false;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(E) {
xmlhttp = false;
}
}
}
if (!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
return xmlhttp;
}
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.status == 200) {
var htmlDocument = http.responseText;
if (htmlDocument!="") {
document.getElementById("text2").value = htmlDocument ;
}
} else {
alert("请求发生异常!");
alert(http.status);
}
}
}
function queryText2() {
var url = "../queryServlet?text1="+document.getElementById("text1").value;
http.open("GET",url,true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
return;
}
<td>
<html:text property="text1" styleId="text1" onblur="queryText2()"/>
</td>
<td>
<html:text property="text2" styleId="text2"/>
</td>
<script type="text/javascript">
var xmlHttpReq;
//创建XMLHTTP对象
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}else if(window.XMLHttpRequest){
xmlHttpReq = new XMLHttpRequest();
}
}
function show(val){
document.getElementById("***").style.display='';
document.getElementById("***").innerHTML="<font color=red size='4'>正在查询数据库,请稍等...</font>";
createXMLHttpRequest();
var url="Ajax.jsp?rand=" + Math.random() + "&val="+val;
xmlHttpReq.open("GET",url,true);
xmlHttpReq.onreadystatechange = showResult;
xmlHttpReq.send(null);
}
function showResult(){
if(xmlHttpReq.readyState == 4){
if(xmlHttpReq.status == 200){
var zap=trim(xmlHttpReq.responseText);
//下拉框。。。。。。
}
}
}
</script>
<%
String sql="";
StringBuffer sb=new StringBuffer();
if(request.getParameter("val")!=null){
val=request.getParameter("val");
sql="*************";
}
//连接数据库
try{
rs = stmt.executeQuery(sql);
if(rs.next()){
sb.append(rs.getString(1)+",");
*******
}
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
**********
}
out.print(sb.toString());
%>