aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Ajax problem while loading option." Watch "Ajax problem while loading option." New topic
Author

Ajax problem while loading option.

Vishal Maga
Greenhorn

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.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");

PrintWriter out = response.getWriter();

DomainFormGetDAO dao1 = new DomainFormGetDAO();

String buffer = dao1.getXmlData();
if(buffer.equals("") == false)
out.write(buffer);
else{
System.out.println("buffer is null---"+buffer);
}
return(null);
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")
{
try{
// Assigning the value to a Drop-Down Set Element
optn.value = val[0].firstChild.data
} catch(er){
}
}
// Checking for the tag which holds the Text of the Drop-Down combo element
tex = x[i].getElementsByTagName("text")
{
try{
// Assigning the Text to a Drop-Down Set Element
optn.text = tex[0].firstChild.data
} catch(er){
}
}
// Adding the Set Element to the Drop-Down

document.form.selectedDomain.options.add(optn)
}
}else{

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>
</html:select>
</td>

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
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

"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.

bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishal Maga
Greenhorn

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: http://aspose.com/file-tools
 
subject: Ajax problem while loading option.