同じページのdivクラスにビュー応答(AJAX呼び出し)を設定しても、ページが新しいページ(ビュー)にリダイレクトされています。 Ajaxの呼び出しは成功し、コンソールでその応答を見ることができました。divへのajax応答を設定した後のリダイレクト
home.jspを:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Gen</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<spring:url value="/resources/css/gen.css" var="mainCss" />
<spring:url value="/resources/js/gen.js" var="mainJs" />
<link href="${mainCss}" rel="stylesheet" />
<script type="text/javascript" src="${mainJs}"></script>
</head>
<body id="layout">
<div id="header">
<h1>XYZ</h1>
</div>
<div id="top-nav">
<ul id="top-nav-list">
<li class="top-nav-list-item" id="gen">
<a class="top-nav-links" id="requestui" href="getrequestui">Generate</a>
</li>
</ul>
</div>
<div id="container">
</div>
</body>
</html>
gen.js
$(document).ready(function(){
$('#requestui').on('click',function(){
var urlBuild = '/gen/getrequestui';
$.ajax({
url: urlBuild,
type: "POST",
async: false,
success: function (response) {
$("#container").html(response);
},
});
});
});
ここをクリック:デフォルトの動作を防止する必要があります。 http://stackoverflow.com/questions/12648916/jquery-capture-anchor-href-onclick-and-submit-asynchronously and here http://stackoverflow.com/questions/788463/how-can-i-intercept-a -link-with-a-ajax-callを使用するjquery –