Last active
August 29, 2015 14:17
-
-
Save adit2787/dad3edb6882b3916de99 to your computer and use it in GitHub Desktop.
Ajax in Spring Portlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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