我的jsp中有以下javascript代码
<script type="text/javascript" src="JS/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#ibutton').click(function(e) {
e.preventDefault();
$.ajax({
url: "search",
type: "post",
data: value,
cache: false,
success: function(data) {
$("#message").html(data).slideDown('slow');
}
});
});
});
</script>
以及以下表格:
<form action="search" name="sub" id="sub">
<input name="search" type="text">
<input type="button" id="ibutton" value="Saveme"/>
</form>
这是我的servlet:
@RequestMapping(value="/search", method = RequestMethod.POST)
public String search(HttpServletRequest req, @RequestParam String search){
req.setAttribute("result", search);
System.out.println("entered");
return "search";
}
当我点击按钮&#34; Saveme&#34;页面没有重定向,但我希望看到&#34;进入&#34;写在控制台,但我不,这是为什么?
我使用以下页面作为参考: http://www.java4s.com/jquery-tutorials/submit-form-without-refreshing-page-in-javajsp-with-jquery/