I return a map to the post method, which is correctly displayed in alert function. How do I append the values of the map to the select option with id course?
<script type="text/javascript" >
$(document).ready(function(){
$("select#dept").change(function(){
alert("inside jquery1");
$.post("getCourses.htm",{depName: $(this).val()}, function(j){
$.each(j, function(key, value) {
alert(key + ': ' + value);
});
});
});
});
</script>
</head>
<body>
<h6>Set Course Fee</h6>
<form:form method="POST" commandName="courseFee">
<table cellspacing="7">
<tr>
<td>Department:</td>
<td><form:select path="pk.dept" id="dept">
<form:option value="select" label="select"/>
<form:options items="${deptList}"/>
</form:select></td>
开发者_如何学运维</tr>
<tr>
<td>Course:</td>
<td><form:select path="pk.course" id="course">
</form:select></td>
</tr>
<tr>
<td><input type="submit" value="Save" ></td>
</tr>
</table>
</form:form>
I would try this:
$.post("getCourses.htm",{depName: $(this).val()}, function(j){
var opts = '';
$.each(j, function(key, value) {
opts += '<option value="'+value+'">'+key+'</option>';
});
$('#course').html(opts);
});
精彩评论