블로그 이미지
박공명

카테고리

분류 전체보기 (99)
된장 (7)
Dev (60)
꼐..꼐임 (6)
식탐 (18)
우리 (0)
Etc (8)
개인자료 (0)
Total
Today
Yesterday

'ajax'에 해당되는 글 1건

  1. 2010.06.14 ajax 간단한 처리

ajax 간단한 처리

Dev/Javascript / 2010. 6. 14. 13:54

var xmlHttp = null;
function getXMLHttpRequest() {
      if (window.ActiveXObject) {
          try {    //IE 에서 XMLHttpRequest
                  return new ActiveXObject("Msxml2.XMLHTTP");
         } catch(e) {
             try {
                     return new ActiveXObject("Microsoft.XMLHTTP");
                 } catch(e1) { return null; }
         }  
     } else if (window.XMLHttpRequest) {
           return new XMLHttpRequest();
     } else {
         return null;
     }
}

이걸루 각 브라우저에 맞게 일단 객체부터 구해온후에

function startRequest() {
    xmlHttp = getXMLHttpRequest();
    xmlHttp.onreadystatechange = onStateChange;
    //xmlHttp.open("GET", "/source/login/simpleResponse.xml", true);
    xmlHttp.open("POST", "/source/login/chkId.php?stringId="+document.all.stringId.value, false);
    alert("send = " + document.all.stringId.value);
    //xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlHttp.send("stringId=kkkkk");
}

전달방법 세팅하구 send 한다.
헤더를 설정 안했을시 POST로 안보내지는 현상을 발견했다.
GET , POST 둘다 같이보내지드라.

function onStateChange() {
 //alert("xmlHttp.readyState = " + xmlHttp.readyState + "  xmlHttp.status = " + xmlHttp.status);
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            alert("서버로부터의 응답 : " + xmlHttp.responseText);
            
        }
    }
}

응답을 받구 완료됬을시 해당페이지의 출력내용을 그대로 받아온다. 얼싸조쿤


'Dev > Javascript' 카테고리의 다른 글

SyntaxHighlighter 적용  (0) 2011.04.21
validation check  (0) 2010.09.11
-1072896658  (0) 2010.06.11
Posted by 박공명
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함