Reputation: 35
I want to display on my website how many players are playing in other poker site. This link provides the data i need in JSON (tournaments.summary.players). I use .getJSON request but it seems that it does not retrieve the data. Here is the script I use:
// 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>
Upvotes: 0
Views: 113
Reputation: 3384
If you look in your console you will probably see something like this
"XMLHttpRequest cannot load http://www.psimg.com/datafeed/dyn_banners/summary.json.js. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."
This means that the link you are trying to download is not enabled for cross origin resource sharing.
See this answer for more Get a JSON file from URL and display
Upvotes: 1