반응형
ajax 테스트를 위한 코드(IE6 확인필요)
테스트 URL : http://db.garada.co.cc/ajaxtest.html
XMLHTTPRequest 객체에 대한 더많은 설명을 보려면
http://www.w3.org/TR/XMLHttpRequest/
https://developer.mozilla.org/ko/XMLHttpRequest
참고.
테스트 URL : http://db.garada.co.cc/ajaxtest.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function ajaxload(divid, url){
var page_request = false
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else
return false
var ajaxfriendlyurl=url.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
page_request.onreadystatechange=function(){
if(page_request.readyState==4 && page_request.status == 200 && page_request.statusText=='OK') {
//로딩되면 할일을 여기에 적는다. 긴 내용이 필요하다면 callback 함수를 외부에 정의해서 사용
//alert(page_request.responseText);
document.getElementById(divid).innerHTML=page_request.responseText;
}
}
//변경된 페이지를 받기위한 더미값
var bustcache=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', ajaxfriendlyurl+bustcache, true)
page_request.send(null)
}
setInterval("ajaxload(\"result\",\"http://db.garada.co.cc/rand.php\")", 1000); //1000(1초간격으로 실행: 주기적)
//-->
</SCRIPT>
</HEAD>
<BODY>
<div id="result"></div>
<input type='button' onclick='ajaxload("result", "http://db.garada.co.cc/rand.php")' value='Change Text'/>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function ajaxload(divid, url){
var page_request = false
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else
return false
var ajaxfriendlyurl=url.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
page_request.onreadystatechange=function(){
if(page_request.readyState==4 && page_request.status == 200 && page_request.statusText=='OK') {
//로딩되면 할일을 여기에 적는다. 긴 내용이 필요하다면 callback 함수를 외부에 정의해서 사용
//alert(page_request.responseText);
document.getElementById(divid).innerHTML=page_request.responseText;
}
}
//변경된 페이지를 받기위한 더미값
var bustcache=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', ajaxfriendlyurl+bustcache, true)
page_request.send(null)
}
setInterval("ajaxload(\"result\",\"http://db.garada.co.cc/rand.php\")", 1000); //1000(1초간격으로 실행: 주기적)
//-->
</SCRIPT>
</HEAD>
<BODY>
<div id="result"></div>
<input type='button' onclick='ajaxload("result", "http://db.garada.co.cc/rand.php")' value='Change Text'/>
</BODY>
</HTML>
XMLHTTPRequest 객체에 대한 더많은 설명을 보려면
http://www.w3.org/TR/XMLHttpRequest/
https://developer.mozilla.org/ko/XMLHttpRequest
참고.
반응형
'개발도 하냐?' 카테고리의 다른 글
HTML vs XHTML? (0) | 2009.12.01 |
---|---|
웹표준 가입폼 (0) | 2009.11.30 |
FLEX AIR - 케이웨더 날씨 모듈 (0) | 2009.11.18 |
FLEX AIR 시스템트레이에 프로그램 넣기 (0) | 2009.11.18 |
The value for the useBean class attribute... (0) | 2009.11.16 |