1
我是JSP新手。 我的问题是,我想改变我的JSP页面内容使用AJAX按钮点击事件.. 我该怎么做..?如何使用连接Servlet的jQuery 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' servlet的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 ..
阅读[AJAX](http://api.jquery.com/jQuery.ajax/) – vinayakj