• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax problem while loading option.

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Vishal Maga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got that my xml string is not getting forwarded to jsp.
Is there any problem in my above mentioned action.Please help.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic