Posted By:
Lee_Dan
Posted On:
Monday, December 25, 2006 01:24 AM
acctually I imitated Philip McCarthy's cart example. but I couldn't get same result. 1. send parameter to servlet var queryString = "SelectWarehouse=" + param; var handlerFunction = getReadyStateHandler(xmlhttp4 , updateStockQty ); var youRL = "/StockQtyArryServlet"; xmlhttp4.open("POST", youRL, true); xmlhttp4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp4.onreadystatechange = handlerFunction; xmlhttp4.send(queryString); 2. here's servlet code pstmt = con.prepareStatement(query); pstmt.setString(1, StorageCd); rs = pstmt.exe
More>>
acctually I imitated Philip McCarthy's cart example. but I couldn't get same result.
1. send parameter to servlet
var queryString = "SelectWarehouse=" + param;
var handlerFunction = getReadyStateHandler(xmlhttp4 , updateStockQty );
var youRL = "/StockQtyArryServlet";
xmlhttp4.open("POST", youRL, true);
xmlhttp4.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp4.onreadystatechange = handlerFunction;
xmlhttp4.send(queryString);
2. here's servlet code
pstmt = con.prepareStatement(query);
pstmt.setString(1, StorageCd);
rs = pstmt.executeQuery();
response.setContentType("application/xml");
response.setHeader("Cache-Control", "no-cache");
out.println ("
<?xml version="1.0"?>");
while (rs.next()) {
out.println ("
");
out.println ("
");
out.println ("
");
out.println (rs.getString("GOODS_NM"));
out.println ("
");
out.println ("
");
out.println (rs.getString("STORE_QTY"));
out.println ("
");
out.println ("
");
out.println ("
");
3. then retrieve this xml object here
function getReadyStateHandler( xmlhttp4, responseXmlHandler) {
return function () {
if (xmlhttp4.readyState == 4) {
if (xmlhttp4.status == 200) {
responseXmlHandler(xmlhttp4.responseXML);
} else if (xmlhttp4.status == 404) {
//error
alert("Request URL does not exist");
} else {
//error
alert("Error: status code is " + xmlhttp4.status);
}
}
}
}
4. finally I want to test this xml object whether to correct like this
function updateStockQty (responsedXML){
items =
responsedXML.getElementsByTagName("item");
alert(items.length);
}
Q1. but javascript returns 0, I am not sure that xml file was created properly. how can I prove it?
Q2. I tried to use various DOM command but it didn't work.
thanks in advance and Merry X-mas
<<Less