【问题标题】:Styling JSON format of iplocate.io样式化 iplocate.io 的 JSON 格式
【发布时间】:2019-04-06 03:22:58
【问题描述】:

我正在使用 iplocate.io 网站来显示知道其 IP 地址的用户的位置。代码效果很好,但我需要对显示进行样式设置,使其看起来比 Json 格式更好。

有没有办法在我自己的页面中显示结果以设置 JSON 格式的显示样式?

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

提前致谢

【问题讨论】:

    标签: geolocation


    【解决方案1】:

    由于我不断的研究,我在这里找到了帮助:[How to create HTML table based on JSON

    How to create HTML table based on JSON

    我以下面的代码为例,使json数据动态化。

    <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);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 2015-12-18
      • 2011-10-09
      • 1970-01-01
      • 2014-02-05
      • 2021-07-03
      • 1970-01-01
      相关资源
      最近更新 更多