We shall display the search results as an ordered list.
var resultHtml=???
???;
Obtain the node list of the Result elements in the Web Service
response using the getElementsByTagName() method. Each of the
Result elements contains a web page returned by the Web Service.
214 10 Web Search with Ajax
var
resultList=xmlMessage.getElementsByTagName(???Result???);
Iterate over the result set to construct the HTML string to update the
web page with. We shall display the web page title, the URL to the web
page and a summary of the web page.
var len =resultList.length;
for(var i=0; ivar result=resultList[i];
var
title=result.getElementsByTagName(???Title???)[0].first
Child.nodeValue;
var
summary=result.getElementsByTagName(???Summary???)[0].f
irstChild.nodeValue;
var
url=result.getElementsByTagName(???Url???)[0].firstChil
d.nodeValue;
resultHtml+=???- Title:???+??????
+title+ ??? \n???;
resultHtml+=???Summary: ???+summary+??????;
}
resultHtml+=???
???;
Set the value of the searchResults
as the string
constructed from the Web Service response.
searchResults.innerHTML=resultHtml;
The complete input.jsp is listed below.
Transitional//EN???
???http://www.w3.org/TR/html4/loose.dtd???>
<%@ page contentType=???text/html;charset=windows-
1252???%>
content=???text/html; charset=windows-1252???/>
input