不要在每个jsp页面(abc.js,def.jsp)中放置表单标签,并在标签页中处理form1的提交事件..
您需要将提交按钮放在最后一个选项卡的 jsp 页面中。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> </title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function () {
$("#tabs").tabs({
beforeLoad: function (event, ui) {
ui.jqXHR.error(function () {
ui.panel.html("Couldn't load this tab.");
});
}
});
// handle submit of each form
$('#form1').submit( function (e) {
var form = $(this);
e.preventDefault();
$.ajax({
url: form.attr('action')
, type: form.attr('method')
, data: form.serialize()
, success: function (data) {
alert(data);
}
, error: function (jqXHR, textStatus, errorThrown) {
alert('Error:' + textStatus + ' - ' + errorThrown)
}
});
});
});
</script>
</head>
<body>
<form id="form1" method="post" class="main" action="myservlet">
<div id="tabs">
<ul>
<li>
<a href="1.htm">
Tab 1</a></li>
<li>
<a href="2.htm">
Tab 2</a></li>
</ul>
</div>
</form>
</body>
</html>
每个表单标签都应该正确设置方法和动作属性!