나의 즐겨찾기 | 블로그홈 | 바로가기 바로가기 | 로그인
거기 Open API 공식 블로그를 방문해 주셔서 감사합니다.
블로그  |  사진갤러리  |  동영상갤러리 방명록  |   즐겨찾기 추가

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
 <meta http-equiv="content-type" content="text/html; charset=euc-kr" />
 <title>XML로부터 객체 생성</title>
 
 
 <script type="text/javascript ">
 var ajax = {};
 ajax.xhr = {};

 ajax.xhr.Request = function(url, params, callback, method) {
  this.url = url;
  this.params = params;
  this.callback = callback;
  this.method = method;
  this.send();
 }

 ajax.xhr.Request.prototype = {
  getXMLHttpRequest: function() {
  if (window.ActiveXObject) {
   try {
    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;
  }  
 },
 send: function() {
  this.req = this.getXMLHttpRequest();
  
  var httpMethod = this.method ? this.method : 'GET';
  if (httpMethod != 'GET' && httpMethod != 'POST') {
   httpMethod = 'GET';
  }
  var httpParams = (this.params == null || this.params == '') ? null : this.params;
  var httpUrl = this.url;
  if (httpMethod == 'GET' && httpParams != null) {
   httpUrl = httpUrl + "?" + httpParams;
  }
  this.req.open(httpMethod, httpUrl, true);
  this.req.setRequestHeader(
   'Content-Type', 'application/x-www-form-urlencoded');
  var request = this;
  this.req.onreadystatechange = function() {
   request.onStateChange.call(request);
  }
  this.req.send(httpMethod == 'POST' ? httpParams : null);
 },
 onStateChange: function() {
  this.callback(this.req);
 }
}
 
 
 window.onload = function() {
  new ajax.xhr.Request("http://kr.open.gugi.yahoo.com/service/rgc.php", "appid=VyY1f0DV34G8HA3UnPbygP8VofLY38zM57lJ7wC7HS3qyxGTBiqrfKa7Qqpetfw&latitude=37.4997677193116&longitude=129.0294189453125&output=xml", viewInfo, "GET");
 }
 function viewInfo(req) {
  if (req.readyState == 4) {
   if (req.status == 200) {
    var docXML = req.responseXML;
    var code = docXML.getElementsByTagName("Found")
                     .item(0).firstChild.nodeVal ue;
    if (code == '1') {
     var country = docXML.getElementsByTagName("country")
          .item(0).firstChild.nodeVal ue;
     var state = docXML.getElementsByTagName("state")
                      .item(0).firstChild.nodeVal ue;
     var county = docXML.getElementsByTagName("county")
                      .item(0).firstChild.nodeVal ue;
     var town = docXML.getElementsByTagName("town")
                      .item(0).firstChild.nodeVal ue;

     
     alert(country+state+county+town);
    } else {
     alert("실패");
    }
   } else {
    alert("에러 발생:"+req.status);
   }
  }
 }
 </script>
</head>
<body>
</body>
</html>

브라우져에서xml로 결과가나오는데 이것을 돔을사용해서 접근해서 정보를 가져오려고 하는데 잘안되네요
브라우져실행하면 접근권한이없다고 나오는데 
잘알려주세요

거기오픈API 2008.08.22  13:33

안녕하세요. Ajax를 통해 OpenAPI를 사용하는 경우 일반적으로 Domain이 다른 host의 API호출시 보안경고가 발생합니다. 이것을 해결하기 위해서는 json callback을 이용하시거나, proxy페이지를 두시는 방법을 사용
하셔야 합니다. 감사합니다.

답글쓰기

댓글쓰기

댓글쓰기 입력폼

포스트 목록 닫기

목록보기
 
거기오픈API (gugi_openapi)
프로필     
전체 글보기(57)
알립니다
물어보세요!! 새 댓글이 있습니다.
2009 11월
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
최근 글
블로그 이전합니다~~~..
블로그를 이전합니다....
지도검색
지도 resize 이후..
커스텀오버레이를 삭제하..
HanRSS 로 구독하기Fish 로 구독하기
최근 댓글 전체보기
<a href=&..
<a href=&..
<a href=&..
<a href=&..
감사합니다^^
최근 참조글 전체보기
Xanax.
Cilias.
Soma.
Xanax.
Soma.
 즐겨찾기
 즐겨찾기 글모음
개설일 : 2007/12/10