2015-01-24 4 views
1

d3.xhr을 사용하여 데이터를 업데이트하는 예를 찾고 있었지만 명확한 내용이나 적어도 저의 이해 수준은 보지 못했습니다. 다음이 링크를 가까이하지만 시가 있습니다 from stackoverflow d3.xhr 예 또는 AJAX d3의 방법

  • from mbostock’s block
    1. 나는 주위를 더보고 JQuery와 및 PHP에서이 예제를 발견했다. 나는 그것을 시도하고 코드를 이해한다. d3.xhr 또는 d3.json에서 동일한 코드를 제공하면 감사하겠습니다. BTW, d3.xhr과 d3.json의 차이점은 무엇이며 언제 사용합니까? 미리 감사드립니다.

      <?php 
      // AJAX & PHP example 
      // http://iviewsource.com/codingtutorials/learning-how-to-use-jquery-ajax-with-php-video-tutorial/ 
          if ($_GET['ip']) { 
           $ip = gethostbyname($_GET['ip']); 
           echo($ip); 
           exit; 
          } 
      ?> 
      
      
      <!DOCTYPE html> 
      <html lang="en"> 
          <head> 
           <meta charset="utf-8" /> 
           <title>Get Reverse IP</title> 
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> 
           </script> 
          </head> 
          <body> 
           Please enter a domain name 
           <input type="text" id="searchip"> 
           <div id="resultip"></div> 
           <script> 
            $(document).ready(function() { 
             $('#searchip').change(function(){ 
              $.ajax({ 
               type: "GET", 
               url: "ajax.php", 
               data: 'ip=' + $('#searchip').val(), 
               success: function(msg){ 
                $('#resultip').html(msg); 
               } 
              }); // Ajax Call 
             }); //event handler 
            }); //document.ready 
           </script> 
          </body> 
      </html> 
      
    +0

    d3 xhr/json 문서를 읽었습니까? https://github.com/mbostock/d3/wiki/Requests –

    +0

    나는 그것을했다, 나는 아직도 그것을 얻지 않는다. 좀 더 힌트를 줄 수 있어요? – ngungo

    답변

    1

    해결책을 찾았습니다. 사실 그것은 코딩이 적습니다 :) 나는 그 대답이 누군가에게 유용 할 것을 진심으로 희망합니다.

    <?php 
    // AJAX & PHP example 
        if ($_GET['ip']) { 
         $ip = gethostbyname($_GET['ip']); 
         echo($ip); 
         exit; 
        } 
    ?> 
    
    <!DOCTYPE html> 
    <html lang="en"> 
        <head> 
         <meta charset="utf-8" /> 
         <title>Get Reverse IP</title> 
         <script src="http://d3js.org/d3.v3.min.js"></script> 
        </head> 
        <body> 
         Please enter a domain name 
         <input type="text" id="searchip"> 
         <div id="resultip"></div> 
         <script> 
          d3.select('#searchip').on("change", function() { 
           d3.xhr('xhr.php?ip='+this.value, function(data) { 
            d3.select('#resultip').html(data.response); 
           }) 
          }); 
         </script> 
        </body> 
    </html> 
    
    +0

    니스. d3의 조력자는 인생을 매우 쉽게 만듭니다. –