0

I'm using the site of iplocate.io to display location of user knowing his IP address. The codes works good, but I need to style the display to make it look nicer than the Json format.

Is there a way to display the result in my own page to style the display of JSON format ?

$ip = $_SERVER['REMOTE_ADDR'];
$res = file_get_contents("https://www.iplocate.io/api/lookup/$ip");
var_dump($res);

Thanks in advance

Diasline
  • 625
  • 3
  • 32

1 Answers1

0

Due to my contanst research i found help here : [How to create HTML table based on JSON

How to create HTML table based on JSON

I Took the codes below as example to make the json data dynamic.

<div id="content"></div>

 <?php
 $ip = $_SERVER['REMOTE_ADDR'];
$res = file_get_contents("https://www.iplocate.io/api/lookup/$ip");
 ?>

Jquery

var info=<?=$res?>;
var data = [info ]

$(document).ready(function () {
var html = '<table class="table table-striped">';
html += '<tr>';
var flag = 0;
$.each(data[0], function(index, value){
html += '<th>'+index+'</th>';
});
html += '</tr>';
$.each(data, function(index, value){
html += '<tr>';
$.each(value, function(index2, value2){
html += '<td>'+value2+'</td>';
});
html += '<tr>';
});
html += '</table>';
$('#content').html(html);
});
Diasline
  • 625
  • 3
  • 32