ํฐ์คํ ๋ฆฌ ๋ทฐ
<%@ 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>์ค๋ณต์์ด๋ ์ฒดํฌ</title>
<script type="text/javascript">
window.onload = function() {
//id๋ผ๋ ์์๋ฅผ ์ฐพ๋๋ค.
var id = document.getElementById("id");
//์ด๋ฒคํธ๋ฑ๋ก
id.onkeyup = function() {
//id๊ฐ์ ์ฝ์ด์ ์๋ฒ๋ก ์ ์กํ๋๋ก ํ๋ ํจ์ํธ์ถ
sendRequest(id.value);
}
}
var req = null;
function sendRequest(data) {
//1. xhr ๊ฐ์ฒดํ์
req = getXMLHttpRequest();
if(req == null) {
alert("XMLHttpRequest ๊ฐ์ฒด๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.");
return;
}
//2. xhr ๊ฐ์ฒด์ ํ๋กํผํฐ ์ค์ ๋ฐ ๋ฉ์๋ ํธ์ถ
req.open("POST", "ajax02Process.jsp", true);
req.onreadystatechange = callback;
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//3. ํ๋ผ๋ฏธํฐ ๋ฐ๊ธฐ
var param = "id=" + encodeURIComponent(data);
//4. ์ ์ก
req.send(param); //POST๋ฐฉ์์์๋ ๊ฐ์ ์ง์ ํ๋ค.
}
function callback() {
var check = document.getElementById("check");
if(req.readyState == 4) {
if(req.status == 200) {
//์๋ฒ์์ ๋ณด๋ด์จ ์ ๋ณด๋ฅผ ์ฝ์ด๋ณด์
var receiveData = req.responseText;
if(receiveData == "available") {
//์ฌ์ฉ๊ฐ๋ฅํ ์์ด๋
check.style.color = "green";
check.innerHTML = "์ฌ์ฉ๊ฐ๋ฅํฉ๋๋ค. ";
} else {
//์ด๋ฏธ ์ฌ์ฉ์ค์ธ ์์ด๋
check.style.color = "orange";
check.innerHTML = "์ด๋ฏธ ์ฌ์ฉ์ค์
๋๋ค.";
}
} else {
check.style.color = "red";
check.innerHTML = "์ค๋ฅ : " + req.statusText;
}
}
}
function getXMLHttpRequest() {
//๊ฐ์ฒดํ์ง๊ธฐ๋ฒ์ผ๋ก
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) { return null; }
}
} else {
return null;
}
}
</script>
</head>
<body>
ID : <input type="text" id="id" />
<span id="check"></span>
</body>
</html>
'JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ajax ๋๋ฒ์งธ (0) | 2010.07.13 |
---|---|
ajax ๋๋ฒ์งธ (0) | 2010.07.13 |
Ajax ์์_์ฒ๋ฆฌํ์ด์ง (0) | 2010.07.12 |
Ajax ์์ (0) | 2010.07.12 |
DOM ๊ฐ์ฒด 02 (0) | 2010.07.09 |
- Total
- Today
- Yesterday
- MS-SQL
- ์์์ฌ์ด๋
- 2ne1
- JSON
- JSTL
- ์๋ฆฌ
- ์น์์ด์ ์
- ๋์ค
- Java
- ๊ฒฝ์ ์ฉ์ด
- ๊ธฐํ
- ๋ณต๊ทผ์ด๋
- MySQL
- 8๋ง์ผ
- EL
- ์นด๋ฐ์จ๋ผ์ธ
- ๋ฉ๋ฐฐํ
- JSP
- ์ธํจ์ด
- ํจ์
- JS
- I Don't Care
- jQuery
- Ajax
- ์๋ธ๋ฆฟ
- ์๋ฐ์คํฌ๋ฆฝํธ
- asp
- JavaScript
- Servlet
- php
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |