Skip to content

Instantly share code, notes, and snippets.

@adit2787
Last active August 29, 2015 14:17
Show Gist options
  • Save adit2787/dad3edb6882b3916de99 to your computer and use it in GitHub Desktop.
Save adit2787/dad3edb6882b3916de99 to your computer and use it in GitHub Desktop.
Ajax in Spring Portlet
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:resourceURL id="findState" var="findState" ></portlet:resourceURL>
<script type="text/javascript">
$(document).ready(function(){
$( "#country" ).change(function() {
$.ajax({
url: "${findState}" ,
type: 'POST',
datatype:'json',
data: {
countryName: $("#country").val()
},
success: function(data){
var content= JSON.parse(data);
$('#state').html('');// to clear the previous option
$.each(content, function(i, state) {
$('#state').append($('<option>').text(state.name).attr('value', state.stateId));
});
}
});
});
});
</script>
<b>Change the Country State Change By Ajax</b> <br><br>
Country:
<select id="country" name="country">
<option value="select">Select Country</option>
<option value="india">India</option>
<option value="usa">USA</option>
</select>
<br><br>
State:
<select id="state" name="state">
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment