为什么此代码无法在jQuery中加载json?
PHP代码:
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, "https://api.clashofclans.com/v1/players/8PQRJUG2Q");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'authorization: Bearer mykey'
)); // Clash of Clans API Token
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$api = curl_exec($curl);
$json = json_encode($api);
print_r($json);
and my jquery code :
$.getJSON('rq.php', { tag: '8PQRJUG2Q'}, function(data) {
alert(data.name);
});
PHP似乎是正确的,但是jQuery无法正常工作。