duanbipu1720 2015-07-01 09:08
浏览 751
已采纳

尝试从url中获取JSON / JSONP数据并将结果显示在html网页上

When I enter the url for instance, "www.example.com" I get the return:

{
    shh: {
        id: 3730672,
        name: "Shh",
        profileIconId: 23,
        summonerLevel: 2,
        revisionDate: 1421646418000
    }
}

I am trying to get all this data and displaying it on my website that is HTML. I tried researching and even tried the following code,

$.getJSON('www.example.com', function(data){
    alert(data);
});

But it just displays nothing. Please help!

  • 写回答

3条回答 默认 最新

  • doubo4336 2015-07-01 09:14
    关注

    if your data callback is not empty you can try this :

    { shh: { id: 3730672, name: "Shh", profileIconId: 23, summonerLevel: 2, revisionDate: 1421646418000 } }
    
    
    
    $.getJSON('www.example.com', function(data){ 
      if(data){
        var ssh = data.ssh;
        var ssh_id = ssh.id;
        var ssh_name = ssh.name;
        
        $('.name').html(ssh_name);
        $('.id').html(ssh_id);
      }
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <span class="name"></span> with id:<span class="id"></span>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 代码的修改,添加和运行完善
  • ¥15 krpano-场景分组和自定义地图分组
  • ¥15 lammps Gpu加速出错
  • ¥15 关于PLUS模型中kapaa值的问题
  • ¥15 关于博途V17进行仿真时无法建立连接问题
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题