Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax problem while loading option.

 
Vishal Maga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65337
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic