title: unable to fetch json data from ip url
body: <p>hey guys i am unable to fetch cross domain json data here is my code below which doesn't work </p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;jQuery.getJSON demo&lt;/title&gt;
    &lt;style&gt;
    img {
      height: 100px;
      float: left;
    }
    &lt;/style&gt;
    &lt;script src="js/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="images"&gt;&lt;/div&gt;
  
  &lt;script&gt;
  (function() {
    var furl= "http://192.168.2.36/gemadmin/display.php?callback=?";
    $.getJSON( furl)
      .done(function( data ) {
        console.log(data);
      });
  })();
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this code works properly since its just localhost</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;jQuery.getJSON demo&lt;/title&gt;
    &lt;style&gt;
    img {
      height: 100px;
      float: left;
    }
    &lt;/style&gt;
    &lt;script src="js/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="images"&gt;&lt;/div&gt;
  
  &lt;script&gt;
  (function() {
    var furl= "http://localhost/gemadmin/display.php";
    $.getJSON( furl)
      .done(function( data ) {
        console.log(data);
      });
  })();
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>why is the first version not working ? and what is the solution to make it work? </p>
  
  <p>server code(display.php)</p>
  
  <pre><code>&lt;?php
      include 'config.php';
      $sql = "select * from menu;";
      $result= $mysqli-&gt;query($sql);
      $data = $result-&gt;fetch_all( MYSQLI_ASSOC );
      header('Content-Type: application/json');
      echo json_encode( $data );
      ?&gt;
  </code></pre>
  
  <p><strong>The answer:</strong>
  Found the answer instead of $.getJSON() use $.get and do a json parse 
  example
      
      
      
        
        jQuery.getJSON demo
        
        img {
          height: 100px;
          float: left;
        }
        
        
      
      </p>
  
  <pre><code>&lt;div id="images"&gt;&lt;/div&gt;
  
  &lt;script&gt;
  (function() {
    var furl= "http://localhost/gemadmin/display.php?callback=?";
    $.get( furl)
      .done(function( data ) {
        var obj = JSON.parse(data);
        console.log(obj);
      });
  })();
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>don't forget to add '<strong>callback=?</strong>'to your url</p>