1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2.     pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. <script type="text/javascript" src="js/jquery-3.1.1.js"></script>
  9. </head>
  10. <body>
  11.     <button onclick="send();">전송</button>
  12.     <div id="test"></div>
  13.    
  14.     <script type="text/javascript">
  15.         function send() {
  16.             $.ajax({
  17.                 url: "ajaxTest2.jsp",
  18.                 type: "post",
  19.                 data: {num1 : 10, num2 : 20},
  20.                 success: function(data) {
  21.                     //$.trim() => 앞뒤 공백 제거
  22.                     $("#test").html("10 + 20 = " + $.trim(data));
  23.                 },
  24.                 error: function(data) {
  25.                     alert("error!");
  26.                 }
  27.             });
  28.         }
  29.     </script>
  30. </body>
  31. </html>