1.select要素にId属性を追加します。
2.arrayListを返すmvcコントローラーにajaxメソッドハンドラーを追加します(jsonオブジェクトを返すことをお勧めします)。
3.jquery/javascript で ajax 呼び出しを実行する
JSP コード:
<head>
<link href="<c:url value="/resources/form.css" />" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<c:url value="/resources/jquery/1.6/jquery.js" />"></script>
<script type="text/javascript">
var interval =2000;
setInterval("getServerData()",interval);
function getServerData(){
$.getJSON("/MyApp/data/jsonList", function(response){
$("#selectBox option").remove();
var options = '';
$.each(response, function(index, item) {
options += '<option value="' + item + '">' + item + '</option>';
$("#selectBox").html(options);
});
});
}
</script>
</head>
<body>
<form:form id="form" method="post">
<select id="selectBox">
<select>
</form:form>
</body>
コントローラーコード:
@RequestMapping(value="/data/jsonList", method=RequestMethod.GET)
public @ResponseBody List<String> getDataList() {
List<String> myList = new ArrayList<String>();
myList.add("option1");
myList.add("option2");
myList.add("option3");
myList.add("option4");
return myList;
}
jquery チェックを使用する場合は
、jQuery AJAX を使用して選択ボックスのオプションを更新しますか?
よく読んでください:Spring ajax 3.0ページ。