코딩하는 문과생

[Web] 10. MVC 패턴 - AJAX 통신(2) 본문

웹 프로그래밍/Web

[Web] 10. MVC 패턴 - AJAX 통신(2)

코딩하는 문과생 2020. 2. 3. 12:00

[Document에서 스크립트로 비동기 통신]

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
	<!-- a태그를 이용해 매개변수를 포함해 함수를 호출할 수 있다. -->
	<a href="javascript:test('sijune', 10)">링크</a>
	
	
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
	<script type="text/javascript">
	
	//링크를 걸어 다른페이지가 아닌 Modal을 띄워야 하는 상황이 발생할 경우
	function test(id, age) {
		alert(id + ", " + age);
		$.ajax({
			url : '',
			type : "",
			data : { id : id, age : age},
			dataType : "json", 
			success : function(obj) {
            
			}
		});
	}
		
	</script>

</body>
</html>