我编写了一个 ajax 函数,当有人从下拉列表中选择年份时将调用该函数。选择年份后,ajax 将根据传递的 URL 调用 servlet,并且该 servlet 将在属性文件中设置一个值。然而,问题是,在选择年份时,我的ajax block 没有被调用
</tr>
<tr>
<td>Year</td>
<td>
<html:select property="yearId" >
<html:options collection=
"<%=GlobalValues.LIST_MODELYEAR%>"
property="id" labelProperty="value" />
</html:select>
(Required)
</td>
</tr>
<script>
$(document).ready(function()
{
$("#yearId").change(function()
{
var selectedValue = $(this).find(":selected").val();
$.ajax
({
url : "/ModelByYear.do?cID="+selectedValue+'',
});
});
});
</script>
最佳答案
也许您可以在调用 AJAX 之前先检查您构建的 url?
$(document).ready(function()
{
$("#yearId").change(function()
{
var selectedValue = $(this).find(":selected").val();
window.location = "/ModelByYear.do?cID="+selectedValue;
});
});
关于java - JSP不调用ajax函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24781259/