【发布时间】:2011-09-01 06:31:15
【问题描述】:
我试图在提交表单后显示成功消息。我使用来自link的jQuery表单插件
并且提交工作正常。就这样:
$('#emailForm').ajaxForm();
现在我想在提交按钮下添加一条成功消息,所以我在下面添加了一个 div:
<input name="submit" type="submit" value="#springMessage('action.save')" />
<div id="emailSuccessMessage">
</div>
并对 jQuery 代码添加一些更改:
var options = {
target: '#emailSuccessMessage',
success: showResponse
};
$('#emailForm').ajaxForm(options);
function showResponse(responseText, statusText) {
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
我的控制器方法是:
@RequestMapping(value = "/password", method = RequestMethod.POST)
public String changePassword(@Valid @ModelAttribute("editPassword") EditPasswordForm editPasswordForm, BindingResult result) {
if (result.hasErrors()) {
return "editAccount";
}
userService.changePassword(editPasswordForm);
return "editAccount";
}
现在当我尝试提交时,它可以工作,但没有显示警报(我添加了一个警报只是为了测试)。 showResponse 方法是如何工作的?我是 jQuery 新手,我想知道如何实现我的目标。我应该在哪里设置 responseText?
谢谢
大卫
【问题讨论】:
-
看起来从来没有调用成功的函数 showResponse.. 为什么?
标签: jquery ajax forms spring-mvc