2014-11-24 145 views
0

我想在我的网站上显示有多少玩家在其他扑克网站上玩。 This link在JSON(tournaments.summary.players)中提供了我需要的数据。我使用.getJSON请求,但它似乎不检索数据。下面是该脚本我用:提取外部网站的json数据

// url used to get the JSON data 
 
var pkrStats = "http://www.psimg.com/datafeed/dyn_banners/summary.json.js"; 
 

 
$.getJSON(pkrStats, function (json) { 
 

 
    // Set the variables from the results 
 
    var playersN = json.tournaments.summary.players; 
 
    console.log('Total players : ', playersN); 
 

 
    // Set the table td text 
 
    $('#players').text(playersN); 
 

 
}); 
 

 
// Caching the link jquery object 
 
var $myLink = $('a.myLink'); 
 

 
// Set the links properties 
 
$myLink.prop({ 
 
    href: pkrStats, 
 
    title: 'Click on this link to open in a new window.' 
 
}).click(function (e) { 
 
    e.preventDefault(); 
 
    window.open(this.href, '_blank'); 
 
});
body { 
 
    font-size: 75%; 
 
    font-family:"Segoe UI", Verdana, Helvetica, Sans-Serif; 
 
} 
 
#body { 
 
    clear: both; 
 
    margin: 0 auto; 
 
    max-width: 534px; 
 
} 
 
table { 
 
    border-collapse: collapse; 
 
    border-spacing: 0; 
 
    margin-top: 0.75em; 
 
    border: 0 none; 
 
    margin-top:35px; 
 
} 
 
#body td { 
 
    padding:15px 30px 15px 10px; 
 
} 
 
#body tr td:nth-child(1) { 
 
    font-weight:bold; 
 
} 
 
#address { 
 
    width:400px; 
 
}
<div id="body"> 
 

 
    <hr/> 
 
    <table border="1"> 
 
     <tr> 
 
      <td>Url:</td> 
 
      <td><a class="myLink">json.js</a> 
 
      </td> 
 
     </tr> 
 
     <tr> 
 
      <td>Users playing:</td> 
 
      <td id="players"></td> 
 
     </tr> 
 
    </table> 
 
</div>

+1

我不确定,但它不应该是一个启用CORS-JSONP /请求? – gustavohenke 2014-11-24 01:13:15

回答