jquery로 구현하게 되면 매우 간단하나.. 오늘은 샘플로 올려 놓고자 합니다..
아래와 같이 구현하시면 될 것 같습니다.
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
alert(xmlhttp.responseText);
}
else{
//alert(xmlhttp.readyState);
//alert(xmlhttp.status);
}
/*
onreadystatechange = Stores a function (or the name of a function) to be called automatically each time the readyState property changes
readyState = Holds the status of the XMLHttpRequest. Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
status
200: "OK"
404: Page not found
*/
}
xmlhttp.open("GET","http://blog.angeleyes.kr/312",true);
xmlhttp.send();
onreadystatechange에서 else문으로 error를 잡으면 될 것 같습니다.
그리고 cross domain 문제의 경우에는 proxy를 이용한 방법으로 처리하는 것이 좋을 것 같습니다.
proxy 참고 : http://renewal.tistory.com/114
cross domain ajax 참고
http://greatkim91.tistory.com/107
감사합니다.
'Script > JavaScript' 카테고리의 다른 글
| jquery plugin 페이스북 스타일 링크 도우미 (0) | 2012.10.23 |
|---|---|
| jquery plugin 페이스북 스타일 링크 도우미 (0) | 2012.07.26 |
| Javascript, JQuery Xml Parsing (File, String) [Convert string to xml] (0) | 2011.02.28 |
| Javascript, JQuery preventDefault의 이해 (0) | 2011.02.23 |
| javascript iframe에 접근하여 iframe method call (0) | 2010.09.09 |