我的 JSP 页面中有一个表单。我正在使用 Ajax 来调用动作类。它对我来说很好。我得到的结果是一个包含 HTML 页面的变量。
这是我的脚本
$(document).ready(function() {
var form = $('#ComponentForm');
form.submit(function () {
$('#saveComponent').html('Loading...').fadeIn();
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
var ajaxResult=data.html().$("#ajaxContent").html();
alert(ajaxResult);
$('#actionResult').html(ajaxResult);
}
});
return false;
});
});
脚本中的数据获取完整的 JSP 页面,如下所示
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Cache-Control" content="no-store"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/myapp/images/favicon.ico"/>
<title>Application Detail | AppFuse</title>
<link rel="stylesheet" type="text/css" media="all" href="/myapp/styles/lib/bootstrap-2.2.1.min.css" />
<link rel="stylesheet" type="text/css" media="all" href="/myapp/styles/lib/bootstrap-responsive-2.2.1.min.css" />
<link rel="stylesheet" type="text/css" media="all" href="/myapp/styles/style.css" />
<script type="text/javascript" src="/myapp/scripts/script.js"></script>
<script type="text/javascript" src="/myapp/jquery-ui-1.10.0/tests/jquery-1.9.0.js"></script>
<script type="text/javascript" src="/myapp/jquery-ui-1.10.0/ui/jquery-ui.js"></script>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid hometab-header" style="height: 40px;">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand liborder" href="/myapp/">AppFuse</a>
<div class="nav-collapse collapse homepagetabs">
<ul class="nav menuhover">
<li class="liborder active"><a href="/myapp/login">Login</a></li>
<li class="liborder" id="dashboard"><a href="#">Dashboard</a></li>
<li class="liborder"><a href="#">Reports</a></li>
<li class="liborder" id="enterprise"><a href="#">Enterprise</a></li>
</ul>
</div>
<div id="ajaxContent" class="container-fluid includestyle">
<table id="ComponentList" class="table table-condensed table-hover">
<thead>
<tr>
<th class="sortable">
<a href="?d-6712549-s=0&d-6712549-o=2&appKey=6">Component Key</a></th>
<th class="sortable">
<a href="?d-6712549-s=1&d-6712549-o=2&appKey=6">Alternate Id</a></th>
<th class="sortable">
<a href="?d-6712549-s=2&d-6712549-o=2&appKey=6">Client Key</a></th>
<th class="sortable">
<a href="?d-6712549-s=3&d-6712549-o=2&appKey=6">Component Desc</a></th>
<th class="sortable">
<a href="?d-6712549-s=13&d-6712549-o=2&appKey=6">Technology Owner Key</a></th></tr></thead>
<tbody><tr class="empty"><td colspan="14">Nothing found to display.</td></tr></tbody></table>
</div>
</body>
</html>
所以变量data包含上面的String。从那我怎么能得到Divid="ajaxContent"
?我上面尝试的脚本不起作用。