私はJSPが初めてです。私の問題は、ボタン クリック イベントで AJAX を使用して JSP ページのコンテンツを変更したいということです。
これは私の「AjaxTest」JSP ファイルです
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
$(document).ready(function () {
$('#GetData').click(function () {
<%--
I want correct codes here,
that connects to my 'AjaxData' servlet
and get it's xml content by tags
and place them in '#PlaceData' paragraph.
--%>
});
</script>
</head>
<body>
<button id="GetData" onclick="loadData">Load</button>
<p id="PlaceData"></p>
</body>
</html>
これは私の「AjaxData」サーブレット GET メソッドです
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<person1>"
+ "<firstname>"
+ "Indunil"
+ "</firstname>"
+ "<lastname>"
+ "Girihagama"
+ "</lastname>"
+ "</person1>";
response.getWriter().write(content);
}
jQuery AJAX を使用して問題を解決するための正しいコードを教えてください。