AJAX 실험

<!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">
var ajax_responseText=null; //전역변수 : 일반 함수와 전송하기위해서 사용
var ajax_responseBody=null;
var ajax_responseXML=null;

var mins_ajax = function(){ //-------- 아작스 기본형을 만들기 위한 클래스
    this.xmlHTTP            =  null;
 if(!this.xmlHTTP){
  if(window.XMLHttpRequest){
   this.xmlHTTP    = new XMLHttpRequest();
  }
  else {
   this.xmlHTTP    = new ActiveXObject("Microsoft.xmlHTTP");
  }
 }  
}
mins_ajax.prototype.open = function(sMethod,sUrl,bAsync){
 if(!this.xmlHTTP) return false;
 //method :  GET,POST,HEAD,PUT,DELETE,MOVE,PROPFIND,PROPPATCH,MKCOL,COPY,LOCK,UNLOCK,OPTIONS
 var xmlHTTP = this.xmlHTTP;
 xmlHTTP.open('GET',sUrl,true);
 //xmlHTTPRequest.open(sMethod, sUrl [, bAsync] [, sUser] [, sPassword])
 xmlHTTP.onreadystatechange = function() {
  //이속에서 this는 밖의 this.xmlHTTP 와 같다
  // readyState 가 4 고 status 가 200 일 경우 올바르게 가져옴
  // xmlHTTP.readyState
  // 0 (Uninitialized), 1 (Open), 2 (Sent), 3 (Receiving), 4 (Loaded)
  if(xmlHTTP.readyState==4 && xmlHTTP.status == 200 && xmlHTTP.statusText=='OK') {
   //성공
   this.xxx = xmlHTTP.responseText;
   //alert('준비상태:'+xmlHTTP.readyState); 
   ajax_responseText= xmlHTTP.responseText;
   ajax_responseBody= xmlHTTP.responseBody;
   ajax_responseXML= xmlHTTP.responseXML;
  }else{ //실패
   ajax_responseText=null; 
   ajax_responseBody=null;
   ajax_responseXML=null;  
   //alert('준비상태:'+xmlHTTP.readyState); 
  }
 }
 xmlHTTP.send('');
// alert(xmlHTTP.responseText); 
}
mins_ajax.prototype.test = function(){
 if(temp)
 alert('네용2'+temp);
 else
 setTimeout(this.test,500);
}
mins_ajax.prototype.getXML = function(){
 if(ajax_responseXML) getXML_act(); //내용이 있다면 동작 함수를 실행한다.
 else setTimeout(this.getXML,500);
}
mins_ajax.prototype.getText = function(){
 if(ajax_responseText){//내용이 있다면 동작 함수를 실행한다.
 getText_act();
 }
 else {
 setTimeout(this.getText,500);
 }
}
mins_ajax.prototype.getBody = function(){
 if(ajax_responseBody) getBody_act();
 else  setTimeout(this.getBody,500);
}
//---------------- 아작스 클래스의 해당 동작 부분. 일반 함수이다.이곳을 수정해서 동작하게 해야한다.
getText_act = function(){
// alert(ajax_responseText);
// alert('Text : 로드완료');   
 document.getElementById('test').value = ajax_responseText;
}
getBody_act = function(){
// alert(ajax_responseXML);
// alert('Body : 로드완료'); 
}
getXML_act = function(){
// alert(ajax_responseXML);
// alert('XML : 로드완료');
}
</script>
<script>
var test = new mins_ajax;
//alert('성공:1');
test.open('GET','http://www.phpschool.com/gnuboard4/bbs/rss.php?bo_table=qna_html',true);
test.getText();
//test.getBody();
//test.getXML();
</script>
<script>
function ajax_view(){
alert('동작');
 url = document.getElementById('txt_url').value;
 test.open('GET',url,true); 
 test.getText(); 
}
</script>
</head>

<body>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>URL :
    <input name="txt_url" type="text" id="txt_url" value="
http://www.phpschool.com/gnuboard4/bbs/rss.php?bo_table=qna_html" size="100">
    <input type="button" name="Submit" value="동작" onclick="ajax_view();"></td>
  </tr>
  <tr>
    <td><textarea name="test" cols="140" rows="40" id="test"></textarea></td>
  </tr>
</table>
</body>
</html>

댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
4.28
4.29
4.30
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
5.11
5.12
5.13
5.15
5.16
5.17
5.18
5.19
5.20
5.21
5.22
5.23
5.24
5.25
5.26
5.27
5.28
5.29
5.30
5.31
6.1