Meaningless Drivel is fun!
The moose likes Struts and the fly likes Ajax problem while loading option. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Ajax problem while loading option." Watch "Ajax problem while loading option." New topic

Ajax problem while loading option.

Vishal Maga

Joined: Nov 27, 2007
Posts: 11
Hi All,

I wanted to load option collection from database using javascript in ajax way. for that i created the xml from back end in my action class as shown below.
response.setHeader("Cache-Control", "no-cache");

PrintWriter out = response.getWriter();

DomainFormGetDAO dao1 = new DomainFormGetDAO();

String buffer = dao1.getXmlData();
if(buffer.equals("") == false)
System.out.println("buffer is null---"+buffer);
and in my js code is
function processRequest() {
if (req.readyState == 4) {
if (req.status == 200) {
// Building a DOM parser from Response Object
var response = req.responseXML.documentElement

//var message = req.responseXML.getElementsByTagName("hello")[0].childNodes[0].nodeValue;
var x = response.getElementsByTagName("option")
var val
var tex
var optn
alert(" XML size"+x.length)
for(var i = 0;i < x.length; i++){

optn = document.createElement("OPTION")
var er
// Checking for the tag which holds the value of the Drop-Down combo element
val = x[i].getElementsByTagName("val")
// Assigning the value to a Drop-Down Set Element
optn.value = val[0]
} catch(er){
// Checking for the tag which holds the Text of the Drop-Down combo element
tex = x[i].getElementsByTagName("text")
// Assigning the Text to a Drop-Down Set Element
optn.text = tex[0]
} catch(er){
// Adding the Set Element to the Drop-Down


alert("Problem retrieving XML data")

and i m jsp is

<td align="left" bgcolor="#F3F3F3" class="smallwhitetext"><html:select property="selectedDomain" > <html ption value="-1">pick one</html ption>

but when i run my jsp i alway get 'xmlhttp' is undefined.
and my dropdown is alway blank.

Please help me.Thanks in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

"Vishal T R", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are disabled.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Vishal Maga

Joined: Nov 27, 2007
Posts: 11
I got that my xml string is not getting forwarded to jsp.
Is there any problem in my above mentioned action.Please help.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I have to assume that your error message ('xmlhttp' is undefined) is coming from JavaScript other than what you have posted. Post your code where 'xmlhttp' is referenced and maybe somebody could help.

- Brent
I agree. Here's the link:
subject: Ajax problem while loading option.
jQuery in Action, 3rd edition