2014-11-24 2 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

내가 확실 해요,하지만이 JSONP/CORS 지원 요청을하지해야합니까? – gustavohenke

답변

1

당신은 아마이

"http://www.psimg.com/datafeed/dyn_banners/summary.json.js를로드 할 수 없습니다 XMLHttpRequest의 없음 '액세스 제어가-허용 같은 것을 볼 수 있습니다 -Origin '헤더가 요청 된 리소스에 존재하므로'null '원본은 액세스가 허용되지 않습니다. "

즉, 다운로드하려는 링크가 원본 상호 리소스 공유를 사용할 수 없음을 의미합니다.

는이 대답을 자세한 Get a JSON file from URL and display

관련 문제