ํฐ์คํ ๋ฆฌ ๋ทฐ
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>ajax01</title>
<script type="text/javascript">
window.onload = function() {
//id๋ผ๋ ์์ด๋๋ฅผ ๊ฐ์ง์์ ๊ฒ์
var id = document.getElementById("id");
//์ด๋ฒคํธ ๋ฑ๋ก
id.onkeyup = function() {
startEvent();
}
}
function startEvent() {
//====================================================================
//1. XMLHttpRequest๊ฐ์ฒด์์ฑ
var req = null;
//====================================================================
//๊ฐ์ฒด ํ์ง๊ธฐ๋ฒ์ผ๋ก ๊ฒ์ฌ? ํ๋ค.
if(window.XMLHttpRequest) {
//๋นMS์ชฝ ์ด๋ฉด
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
//MS์ชฝ
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = null;
}
}
}
if (req == null) {
alert("XMLHttpRequest๊ฐ์ฒด ์ง์ํ์ง ์์ !!! ");
return;
}
//====================================================================
//id๋ผ๋ ์์๋ฅผ ์ฐพ์
var id = document.getElementById("id");
//id๊ฐ ์ฝ๊ธฐ
var data = id.value;
//====================================================================
//์ด ์ ๋ณด๋ฅผ ์๋ฒ์ ์ฃผ์์ ๋ง๋ถ์ฌ์ผ ํ๋ค.
var url = "ajax01Process.jsp";
url += "?id=" + encodeURIComponent(data);
//get๋ฐฉ์์์๋ url ๋ค์ ํ๋ผ๋ฏธํฐ ์ ๋ณด๋ฅผ ์ถ๊ฐํด ๋ณด๋ด์ผ ํ๊ณ ,
//๊ทธ ๋ฐ์ดํฐ๊ฐ URLEncoding๋๋๋ก ์์ ํด์ผ ํ๋ค.
//====================================================================
//2. XMLHttpRequest ๊ฐ์ฒด์ ๋ํ ์ค์
req.open("GET", url, true);
req.onreadystatechange = function() {
//์๋ฒ๋ก๋ถํฐ ์๋ต์ ๋ฐ๋ ๊ณผ์ ์ ์๋ค๋ฉด ํธ์ถ๋๋ ์ฝ๋
// ๋จผ์ ์๋ต์ด ์๋ฃ๋์๋๊ฐ?
if(req.readyState == 4) {
//๊ทธ๋ฆฌ๊ณ ์๋ต์ ๊ฒฐ๊ณผ๊ฐ ์ฑ๊ณต์ ์ธ๊ฐ?
//message๋ผ๋ ์์ด๋ ์์๋ฅผ ์ฐพ์.
var msg = document.getElementById("message");
if(req.status == 200) {
//ํ์ฌ ๋ฌธ์์ DOM์ ์ด์ฉํ์ฌ ๋ถ๋ถ์
๋ฐ์ดํธ ์์
ํ๋ค.
msg.style.color = "blue";
msg.innerHTML = req.responseText;
} else {
//์คํจ์ ์ํ๋ฅผ ๋ฐ์๋ค๋ฉด
msg.style.color = "red";
msg.innerHTML = "์คํจ : " + req.statusText;
}
}
};
req.send(null); //get๋ฐฉ์์์๋ null์ ์ง์ .
}
</script>
</head>
<body>
<input type="text" id="id" />
<div id="message"></div>
</body>
</html>
'JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ajax ๋๋ฒ์งธ (0) | 2010.07.13 |
---|---|
Ajax ์์_์ฒ๋ฆฌํ์ด์ง (0) | 2010.07.12 |
DOM ๊ฐ์ฒด 02 (0) | 2010.07.09 |
DOM ๊ฐ์ฒด 01 (0) | 2010.07.09 |
JSON ์ด์ฉํ ๊ฐ์ฒด toString (0) | 2010.07.09 |
- Total
- Today
- Yesterday
- Servlet
- 2ne1
- ์๋ธ๋ฆฟ
- ๋ฉ๋ฐฐํ
- JS
- Java
- ์๋ฆฌ
- ์์์ฌ์ด๋
- php
- EL
- ์น์์ด์ ์
- MySQL
- ์๋ฐ์คํฌ๋ฆฝํธ
- asp
- JSTL
- I Don't Care
- jQuery
- MS-SQL
- 8๋ง์ผ
- JSON
- ๋ณต๊ทผ์ด๋
- ๊ธฐํ
- ๋์ค
- ํจ์
- JSP
- Ajax
- JavaScript
- ์ธํจ์ด
- ์นด๋ฐ์จ๋ผ์ธ
- ๊ฒฝ์ ์ฉ์ด
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |