-
October 6th, 2007, 12:28 AM
#1
Dynamic display of data to div in Struts with ajax
I am developing an application in struts framework , where i am trying to display some content to the div tag in jsp when a option is selected in drop down box in a <html:form>
i can do this in jsp using onchange=this.form.submit() but i dont want to use this method as it effects the performance of the page display,
So i want to know is there is any other process to develop it
Can any one tell me how to use ajax for this application
Please provide me the information,
Thanks in advance
-
October 6th, 2007, 08:05 AM
#2
Re: Dynamic display of data to div in Struts with ajax
Well, AJAX is s true implementation of JavaScript. The JSP will come into play when you output the server-side code. Sometime like the follow should help you out!
Code:
<script type="text/javascript">
function chkDropDown(obj, url){
var xmlHTTP;
try{xmlHTTP = new XMLHttpRequest();}
catch(e){
try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){
try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHTTP.open('GET', url, true);
xmlHTTP.send(null);
xmlHTTP.onreadystatechange = function(){
if(xmlHTTP.readyState == 4){
populateList(obj, xmlHTTP.responseText);
}
}
}
function popuplateList(obj, results){
obj.length = 0;
var theOptions = results.split(',');
for(i = 0; i < theOptions.length; i++) {
obj.options[i] = new Option(theOptions[i], theOptions[i]);
}
}
</script>
<select name="whatever" onchange="chkDropDown(this, 'path/to/file.jsp')">
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|