1
我試圖基於使用sendxmlRequest()方法eqid從表中獲取值的responseText值:要獲得一個AJAX調用
<select name="eqNAME" onchange="sendxmlRequest('GET','getEquipDetails.jsp',this.value)
<options> ..... <options>
</select>
這我ajax.js文件添加
//Make the XMLHttpRequest Object
var http = createRequestObject();
function sendxmlRequest(method, url,eqid){
url = url + "?eqid="+eqid;
if(method == 'get' || method == 'GET'){
http.open(method,url,true);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
function createRequestObject(){
var req; try {
// Firefox, Opera, Safari
req = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
//For IE 6
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
//For IE 5
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
}
}
}
return req;
}
用於處理響應(在ajax.js)以下:
function handleResponse(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
}
}
這裏是我的「getEquipDetails.jsp」文件:
<%
String planLoc= theResult1.getString(2) == null ? "":theResult1.getString(3);
String changLoc= theResult1.getString(3) == null ? "":theResult1.getString(4)
%>
<%
response.setHeader("Pragma", "no-cache"); //HTTP 1.0
response.setDateHeader("Expires", 0); //prevents caching at the proxy server
response.setHeader("Cache-Control", "no-cache, private, no-store, max-stale=0"); // HTTP 1.1
%>
我的查詢是,我們如何從getEquipDetails.jsp獲取值planLoc和changLoc並將其設置在responseText的,所以它可以更新在我的網頁下拉?
或者還有什麼其他方式可以解決嗎?
注:我沒有給出表檢索代碼,因爲這已經被照顧。我只是想planLoc和changLoc在我的JSP頁面