我正在开发一个 web 应用程序,我必须在不提交表单的情况下显示搜索结果。所以我使用$.ajax()
了jQuery的功能。看看它
$('#search').click(function() {
alert("submit handler has fired");
$.ajax({
url: 'cityResults.htm',
data: $('#cityDetails').serialize(),
type: 'json',
success: function(data){
alert(data);
},
error: function(jqXHR, textStatus, errorThrown){
alert('error: ' + textStatus + ': ' + errorThrown);
}
});
return false;//suppress natural form submission
});
这是我的 HTML 标记。我正在使用 Spring MVC 3 框架
<form:form id="cityDetails" method="post"
action="cityResults.htm">
<table class="tdbgact border">
<tr>
<th>State: <span class="required">*</span></th>
<td>
<form:select path = "state" id = "state">
<form:option value="">---Select</form:option>
<form:options items="${stateList}"/>
</form:select>
</td>
<th><form:checkbox path="status" value="Active"/>Active</th></td>
<td colspan="5"><th><form:checkbox path="status" value="Inactive"/>Inactive</th></td>
<tr>
<td colspan="2"><input type="button" id="search" class="buttonSubmit" value="City" /></td>
</tr>
</tr>
</table>
这是我的控制器代码
@RequestMapping(value = "/cityResults.htm", method = RequestMethod.POST)
public @ResponseBody String schemeResults(ModelMap model ,@ModelAttribute("SpringWeb")CityMaster bean,
BindingResult result) {
functionName = "cityResults";
List<CityMaster> cities = new ArrayList() ;
logger.info("In "+className+" - "+functionName+" ");
if(result.hasErrors())
{
}
else{
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
MasterJDBCTemplate dao =
(MasterJDBCTemplate)context.getBean("masterJDBCTemplate");
String[] cityStatus = bean.getStatus();
if(cityStatus == null)
{
}
cities = dao.cityList(bean);
model.addAttribute("cityList", cities );
}
return cities.get(0).getCity();
}
我在警告框中收到错误参数无效。这意味着我的 ajax 调用失败。这意味着我必须更改我的控制器代码。我必须做哪些改变?或者我还有什么遗漏的。