Search Results for '2010/10/27'


1 POSTS

  1. 2010/10/27 Using XMLHttpRequest object by 좐군

Using XMLHttpRequest object

Using XMLHttpRequest object

이런 저런 설명 필요 없이 바로 소스로...
다음 소스는  XMLHttpRequest를 Get/Post 방식 사용 예제(XmlHttpRequestSample.htm)
<!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">
   <head>
      <title>POST/ GET XHR Example</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />

      <script type="text/javascript">
      var url = "http://www.google.co.uk/search";
      var params = "hl=en&q=ff3+request.open+post+problem&meta=";

      function post()
  {
         var xmlhttp=new XMLHttpRequest();
        
         //
onreadystatechange  이벤트 설정
         xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               DisplayResult(xmlhttp.responseText);
            }
         };

         xmlhttp.open("POST", url, true);
         //Post 방식에서 다음 헤더 지정
         xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         xmlhttp.setRequestHeader("Content-length", params.length);
         xmlhttp.setRequestHeader("Connection", "close");
         xmlhttp.send(params);  //params를 전송
      }

      function get()
      {
         var xmlhttp=new XMLHttpRequest();
        
         xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               DisplayResult(xmlhttp.responseText);
            }
         };

         xmlhttp.open("GET", url+"?"+params, true);
         xmlhttp.send(null);
      }
      
      function DisplayResult(strResult)
      {
document.all["result"].value=strResult;
      }
      </script>
   </head>

   <body>
      <a href="javascript:get();">GET request</a>  실행<br />
      <a href="javascript:post();">POST request</a> 실행
      <br/>
      <textarea name="result" rows="10" cols="80"></textarea>
   </body>
</html>
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2010/10/27 08:48 2010/10/27 08:48
Response
5 Trackbacks , No Comment
RSS :
http://John.tobe30.com/tc/rss/response/324

Trackback URL : http://John.tobe30.com/tc/trackback/324

Trackbacks List

  1. Lana Latimore

    Tracked from Lana Latimore 2011/12/02 03:25 Delete

    Say, you got a nice post.Really thank you! Much obliged.

  2. Benjamin Lamas

    Tracked from Benjamin Lamas 2011/12/19 12:15 Delete

    Hey, thanks for the blog article.Much thanks again. Fantastic.

  3. Sidney Ruark

    Tracked from Sidney Ruark 2011/12/19 21:21 Delete

    Fantastic article post.Really thank you!

  4. Romeo Fay

    Tracked from Romeo Fay 2011/12/22 15:46 Delete

    Really enjoyed this blog. Awesome.

  5. Cael Crissman

    Tracked from Cael Crissman 2012/01/02 13:33 Delete

    Really informative post.Really looking forward to read more. Great.

Leave a comment
[로그인][오픈아이디란?]