所以这是我的app.js
$(document).ready(function(){
$.getJSON("/info.php", function(json){
$.each(json, function(i, player){
//console.log(player.response.players[0].avatarfull);
$(".userinfo").append('<img style="width: 100px; height: 100px" style="width: 100px; height: 100px" src="'+player.response.players[0].avatarfull+'">');
$(".steamProfile").append('<a href="'+player.response.players[0].profileurl+'">STEAM nuoroda</a>');
$(".personaname").append(player.response.players[0].personaname);
});
});
});
这是我的html
<div class="col-md-4">
<div class="userinfo"></div>
<p>Slapyvardis: <strong><span id="personaname"></span></strong></p>
<p>Vardas: <strong>{{$s->fname}} {{$s->lname}}</strong></p>
@if($s->facebook == "")
<p>Facebook: <strong>Nėra</strong></p>
@else
<p>Facebook: <strong>{{$s->facebook}}</strong></p>
@endif
<p>Skype ID: <strong>{{$s->skype_id}}</strong></p>
<p>Steam ID: <strong><span class="steamID">{{$s->steam_id}}</span></strong></p>
<p>Steam URL: <strong><span class="steamProfile"></span></strong></p>
<p style="font-family: 'Roboto', sans-serif;"><button id="reason" data-toggle="modal" data-target="#reasonText{{$s->id}}" class="btn btn-danger"><i class="glyphicon glyphicon-film"></i> Rodyti priežastį</button>
<button data-toggle="modal" data-target="#proofText{{$s->id}}" id="proof" class="btn btn-success">
<i class="glyphicon glyphicon-camera"></i> <strong>Įrodymai</strong></button>
<form id="voteUp" action="/minus-rep/{{$s->id}}" method="get">
<button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-thumbs-down"></i> <strong>Nerekomenduoti</strong></button>
</form>
</p>
<p>Nerekomenduoja: <strong><span id="votes" class="label label-success">{{$s->points}}</span></strong>
@if($s->points < 2 && $s->points > 0)
narys
@endif
@if($s->points > 1 && $s->points < 10)
nariai
@endif
@if($s->points > 10)
narių
@endif
</p>
</div>
这就是结果的显示方式:
它基本上复制了信息并将其显示在同一列中。你能给我任何解决这个问题的建议吗?我正在搜索答案,但我无法将它们附加到我的代码中......
虚拟形象正在重复。它应该只是绿色,在下一栏中是动漫头像
json
$data = [];
foreach($row as $r){
$steamids = $r['steam_id'];
$APIKEY = '***';
$steamAPI = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?steamids=$steamids&key=$APIKEY&format=json";
$json_object= file_get_contents($steamAPI);
$data[] = json_decode($json_object);
}
echo json_encode($data);
Console.log回复
XHR finished loading: GET "http://localhost:8888/info.php"
https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/20/20a65e6289bfbbbf59d4fdb923ad4daf8ca4fd9d_full.jpg
https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/1a/1ae5d70c309e3f9f31bb6cff6104d4dd6e08abcc_full.jpg
答案 0 :(得分:1)
很难说不知道响应是什么,但我认为你可能会使用键'0'直接引用数组的成员,所以它循环通过2个玩家但只使用第一个的数据。而不是
player.response.players[0]...
怎么样
player.response.players[i]...