-
AJAX 시스템 시간 샘플Programming/AJAX 2011. 3. 2. 15:52
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.displaybox{
width:150px;
background-color:#fff;
border:2px solid #000;
padding:10px;
font:24px normal verdana;
}
</style>
<script type="text/javascript">
//브라우저 종류 판별을 이용한 방법
/*
function getXMLHTTPRequest(){
var req = false;
if(window.XMLHTTPRequest){
req = new XMLHTTPRequest();
}else{
if(window.ActiveXObject){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}catch(err){
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
}catch(err){
req = false;
}
}
}
}
return req;
}
*/
// 브라우저에 무관하게 객체 생성
function getXMLHTTPRequest(){
var req = false;
if(window.XMLHTTPRequest){
req = new XMLHTTPRequest();
}else{
if(window.ActiveXObject){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}catch(err){
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
}catch(err){
req = false;
}
}
}
}
return req;
}var http = getXMLHTTPRequest();
function getServerTime(){
var myurl = "telltimeXML.php";
myRand=parseInt(Math.random()*99999999);
var modurl = myurl+"?rand="+myRand;
http.open("GET",modurl,true);
http.onreadystatechange = useHttpResponse;
http.send(null);
}
function useHttpResponse(){if(http.readyState == 4){
if(http.status ==200){
var timeValue = http.responseXML.getElementsByTagName('timenow')[0];
document.getElementById('showtime').innerHTML = timeValue.childNodes[0].nodeValue;
}
}else{
document.getElementById('showtime').innerHTML = '<img src="amin.gif">';
}
}
</script>
</head>
<body style="background-color:#ccc;" onload="getServerTime()">
<center>
<h1>Ajax Demonstration</h1>
<form name="form1">
<input type="button" value="테스트" onclick="getServerTime()">
</form>
<div id="showtime" class="displaybox"></div>
</center>
</body>
</html>'Programming > AJAX' 카테고리의 다른 글
Ajax 기본 강의 문서. (0) 2011.03.02 prototype 사용한 테스트 Ajax 샘플 (0) 2011.03.02 Ajax library 만들어서 사용하기.(샘플) (0) 2011.03.02 AJAX 와 관련된 프레임웍과 라이브러리 (0) 2011.02.12 AJAX 시작하기. (0) 2010.09.29