我正在从下拉列表中向控制器发送一个id(oncgange函数)。它工作正常。现在在控制器中查询数据库结果后存储在arrylist中。我已经给了returntype arrylist。是好的还是有任何错误。请帮忙。我只想显示第一个下拉列表中另一个基于下拉列表的选定值。 假设我选择了水果,所以我想在jsp中填充它。无法通过jquery从控制器获得响应jsp
<option value="mango">Mango</option>
<option value="pineapple">Pineapple</option>
JSP
<script>
function getScode()
{
var code = document.getElementById('code'),
code = code.value;
jQuery.ajax({
type: 'POST',
url: 'scode.htm',
data: {
code: code
},
success: function (html) {
$('#scode_data').html(html).show();
}
});
return false;
}
</script>
Select Genre
<select name="code" id="code" onchange="getScode();">
<option value="1">Fruit</option>
<option value="2">Game</option>
</select>
Under that
<div id="scode_data"></div>
控制器
@RequestMapping(value="/scode", method = RequestMethod.POST)
public @ResponseBody ArrayList getScode(ModelMap modelMap, @RequestParam(value = "code", required = false) String code_val, HttpServletRequest request, HttpServletResponse response)
throws ClassNotFoundException {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource = new dbconnection.connection().getConnection(dataSource);
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = "SELECT * FROM cat WHERE fcode='"+code_val+"'";
srs = jt.queryForRowSet(sql);
while (srs.next()) {
pojo obj2 = new pojo();
obj2.setScode(srs.getString("fcode"));
obj2.setSname(srs.getString("fname"));
arraylist.add(obj2);
}
return arraylist;
}
Image link of what i am getting
您将发送arraylist的json版本。并在成功函数解析您收到的JSON并将其附加到另一个
我现在可以通过ajax获取数据。但它显示...像......的数据列表数据。model.pojo @ 14e79b55model.pojo @ 46162020 ** –
检查浏览器控制台中的成功。 (html){ \t console.log(html); \t $('#scode_data')。html(html).show(); \t }' 您应该获取对象数组。发布那个截图。 –