티스토리 뷰
XMLHttpRequest
} else if (xmlHttp.status == 204) {
alert("전달된 데이터가 없습니다.");
} else if (xmlHttp.status == 404) {
alert("URL을 확인하세요.");
} else if (xmlHttp.status == 500) {
alert("내부 에러!.");
}
}
}
선언 :
var xmlHttp = Ajax.getTransport();
var Try = {
these: function() {
var returnValue;
for (var i = 0; i < arguments.length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
} catch (e) {}
}
return returnValue;
}
}
var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP.4.0')},
function() {return new ActiveXObject('Msxml2.XMLHTTP.3.0')},
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;
}
}
these: function() {
var returnValue;
for (var i = 0; i < arguments.length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
} catch (e) {}
}
return returnValue;
}
}
var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP.4.0')},
function() {return new ActiveXObject('Msxml2.XMLHTTP.3.0')},
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;
}
}
보낼곳
POST방식으로, 특정URL, 비동기(false)
xmlHttp.open("POST", "특정URL", false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send();
xmlHttp.open("GET", "특정URL", false);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send(보낼 값들);
처리
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = xmlCallback;
xmlHttp.send(serialize);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = xmlCallback;
xmlHttp.send(serialize);
function xmlCallback() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
//alert(xmlHttp.responseText);
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
//alert(xmlHttp.responseText);
xmlHttp.responseText(받는 데이터값)
완료되었을때 처리할 로직} else if (xmlHttp.status == 204) {
alert("전달된 데이터가 없습니다.");
} else if (xmlHttp.status == 404) {
alert("URL을 확인하세요.");
} else if (xmlHttp.status == 500) {
alert("내부 에러!.");
}
}
}
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
if (xmlHttp.status == 200) {
readyState
0:open() 수행전
1:send() 수행전 - 로딩중
2:서버가데이터를 받았음 - 로딩만완료
3:받는중
4:완료
status
200:OK
204:내용없음
400:bad Request
403:접근거부
404:존재하지않음
500:서버오류
503:service unavailable
full 소스
function changeArea(AreaCode)
{
if (AreaCode == "")
{
alert("영역을 선택해주세요.");
document.getElementById("divSubjectCode").innerHTML = "";
return;
}
var xmlHttp = Ajax.getTransport();
var serialize = getSerialize(document.searchForm);
var url = "xhrGetSubjectCode.asp?searchArea="+AreaCode+"&searchSubjet=<%=searchSubjet%>&selectName=searchSubjet";
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = xmlCallback;
xmlHttp.send(null);
function xmlCallback() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
//alert(xmlHttp.responseText);
document.getElementById("divSubjectCode").innerHTML = xmlHttp.responseText;
} else if (xmlHttp.status == 204) {
alert("전달된 데이터가 없습니다.");
} else if (xmlHttp.status == 404) {
alert("URL을 확인하세요.");
} else if (xmlHttp.status == 500) {
alert("내부 에러!.");
}
}
}
}
{
if (AreaCode == "")
{
alert("영역을 선택해주세요.");
document.getElementById("divSubjectCode").innerHTML = "";
return;
}
var xmlHttp = Ajax.getTransport();
var serialize = getSerialize(document.searchForm);
var url = "xhrGetSubjectCode.asp?searchArea="+AreaCode+"&searchSubjet=<%=searchSubjet%>&selectName=searchSubjet";
xmlHttp.open("GET", url, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = xmlCallback;
xmlHttp.send(null);
function xmlCallback() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
//alert(xmlHttp.responseText);
document.getElementById("divSubjectCode").innerHTML = xmlHttp.responseText;
} else if (xmlHttp.status == 204) {
alert("전달된 데이터가 없습니다.");
} else if (xmlHttp.status == 404) {
alert("URL을 확인하세요.");
} else if (xmlHttp.status == 500) {
alert("내부 에러!.");
}
}
}
}
아래처럼.~
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 엑스페리아 타블렛 Z
- 구디 포차
- 구로디지털 포차
- 애플 이벤트
- 겨울왕국
- html
- 구로디지털단지역 맛집
- CSS
- classic asp
- 그레이 아나토미 시즌1
- asp 숫자
- Select case
- gt-s55
- 퍼시픽 림
- 이북 만들기
- 윈드러너
- 구디 스파게티
- 북 스캐너
- 태그를 입력해 주세요.
- 대륭포스트타워7차
- awake
- Frozen
- 가입한 보험조회
- 구로디지털단지역
- costco 광명점
- 가산 하이힐
- asp
- 안드레기
- 롯데씨네마
- 글리 시즌1
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함