JSON 배열에서 하나의 값을 얻지 만 어떻게 여러 값을 JSON 배열에 저장할 수 있으며 어떻게 JavaScript로 검색 할 수 있습니까?JSON 배열 객체로 둘 이상의 값을 검색합니다.
auto.jsp :
<script type="text/javascript">
$(document).ready(function() {
$("#combo").change(function() { // after onchange event it goes to combo1.jsp
$.getJSON('combo1.jsp', {
count: this.value
}, function(responseData) {
var splitValues = responseData.name.split(/,/);
$("#combo1").empty().append("<option>please select</option>");
for (var idx in splitValues) {
$("#combo1").append(
$("<option></option>").html(splitValues[idx]).val(splitValues[idx]));
}
});
});
});
</script>
<body>
//first combo box
<select id="combo" name="count">
<option value="">please select</option>
<option value="a">A</option>
</select>
//second combo box
<select id="combo1" name="combo1Val">
// i am getting only "5" here, but i want to show 1,2,3,4,5 as in drop down list
</select>
</body>
combo1.jsp :
<%
String count=request.getParameter("count");// by onchange event of first combo, i am
getting value "a" here
if(count.equalsIgnoreCase("a")){
// in my db there are 5 values i.e. 1,2,3,4,5 for single value "a", but while
populating in second combo i am getting only one value "5", how? please ignore my db
connection in jsp
JSONObject arrayObj= new JSONObject();
// by db connection i am fetching 5 values but while printing in javascript i am
getting only last one that is "5" in second combo, how can i populate all values
1,2,3,4,5 as drop down items in second combo box?
// retrieveing 5 datas(1,2,3,4,5) from db where name =a
while(rs.next()){
t1=(String)(rs.getString(1));// there are 5 values in db relating to "a", but i
am getting only last value i.e. "5" in second combo
}
arrayObj.put("name",t1);
response.setContentType("application/json");
response.getWriter().write(arrayObj.toString());
}
%>
console.log (responseData)로 결과를 확인하고 싶지 않으십니까? – bondythegreat
'JSONArray'를 사용하여'while (rs.next()) { '루프 (즉 5 번) 내에서 항목을 추가해야합니다. –
이 질문을 참조하십시오 : * jQuery와 jsp를 사용하여 동적 드롭 다운 목록을 생성하는 방법? * http://stackoverflow.com/questions/2896730/how-to-generate-dynamic-drop-down-lists-using-jquery- and-jsp –