0

Что я делаю не так?) Так выводит нужную мне информацию.

<?php include ('header.php'); ?>
<?php include ('steamauth/playeruser.php'); ?>
<?php include ('footer.php'); ?>

Но я хочу сделать предзагрузку через ajax. А так не работает:

<?php include ('header.php'); ?>

<script type="text/javascript">
$("document").ready(function(){
   $("#container").load("steamauth/playeruser.php");
});
</script>

<div id="#container"></div>

<?php include ('footer.php'); ?>

steamauth/playeruser.php

<?php

        require 'steamconfig.php';

        function convert_steamid_64bit_to_32bit($id)
        {
                $result = substr($id, 3) - 61197960265728;
                return (string) $result;
        }

        $steamid = $_GET['id'];

    $url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$steamid); 
        $csgourl= file_get_contents("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=".$steamauth['apikey']."&steamid=".$steamid); 
        $dtpurl= file_get_contents("http://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1?key=".$steamauth['apikey']."&appid=570"); 
        $csgotpurl= file_get_contents("http://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1?key=".$steamauth['apikey']."&appid=730"); 
    $baninfourl = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=".$steamauth['apikey']."&steamids=".$steamid); 
        $steamid32 = convert_steamid_64bit_to_32bit($steamid);
        $dsurl= file_get_contents("https://api.opendota.com/api/players/".$steamid32); 
        $dswinloseurl= file_get_contents("https://api.opendota.com/api/players/".$steamid32."/wl"); 
        $dsrecordsurl= file_get_contents("https://api.opendota.com/api/players/".$steamid32."/records"); 
        $content = json_decode($url, true);
        $baninfocontent = json_decode($baninfourl, true);
        $csgocontent = json_decode($csgourl, true);
        $dtpcontent = json_decode($dtpurl, true);   
        $csgotpcontent = json_decode($csgotpurl, true); 
        $dscontent = json_decode($dsurl, true);
        $dswinlosecontent = json_decode($dswinloseurl, true);   
        $dsrecordscontent = json_decode($dsrecordsurl, true);

        /* Обработка данных */
    $communityvisibilitystate = $content['response']['players'][0]['communityvisibilitystate'];
    $profilestate = $content['response']['players'][0]['profilestate'];
    $personaname = $content['response']['players'][0]['personaname'];
    $lastlogoff = $content['response']['players'][0]['lastlogoff'];
    $profileurl = $content['response']['players'][0]['profileurl'];
    $avatar = $content['response']['players'][0]['avatar'];
    $avatarmedium = $content['response']['players'][0]['avatarmedium'];
    $avatarfull = $content['response']['players'][0]['avatarfull'];
    $personastate = $content['response']['players'][0]['personastate'];

    if ($baninfocontent['players'][0]['CommunityBanned']) { 
           $baninfocommunity = "бан обнаружен";
       } else {
           $baninfocommunity = "бан не обнаружен";
    }

    if ($content['response']['players'][0]['personastate'] = 0) { 
           $personastate = "Не в сети";
    } 
        else if ($content['response']['players'][0]['personastate'] = 1) {
           $personastate = "В сети";
    }
        else if ($content['response']['players'][0]['personastate'] = 2) {
           $personastate = "Занят";
    }
        else if ($content['response']['players'][0]['personastate'] = 3) {
           $personastate = "Отошёл (AFK)";
    }
        else if ($content['response']['players'][0]['personastate'] = 4) {
           $personastate = "Спит";
    }
        else if ($content['response']['players'][0]['personastate'] = 5) {
           $personastate = "Хочет обменяться";
    }
        else if ($content['response']['players'][0]['personastate'] = 6) {
           $personastate = "Хочет играть";
    }
        else {
           $personastate = "Статус неизвестен";
    }

    if ($baninfocontent['players'][0]['VACBanned']) { 
           $baninfovac = "бан обнаружен";
       } else {
           $baninfovac = "бан не обнаружен";
    }

    if (isset($content['response']['players'][0]['gameextrainfo'])) { 
           $gameextrainfo = $content['response']['players'][0]['gameextrainfo'];
       } else {
           $gameextrainfo = "Пользователь сейчас не играет";
    }

    if (isset($content['response']['players'][0]['realname'])) { 
           $realname = $content['response']['players'][0]['realname'];
       } else {
           $realname = "Настоящее имя не указано в профиле";
    }

    $primaryclanid = $content['response']['players'][0]['primaryclanid'];
    $timecreated = $content['response']['players'][0]['timecreated'];
        $csgo_total_kills = $csgocontent['playerstats']['stats'][0]['value'];
        $csgo_total_deaths = $csgocontent['playerstats']['stats'][1]['value'];
        $csgo_total_kd = round($csgocontent['playerstats']['stats'][0]['value']/$csgocontent['playerstats']['stats'][1]['value'], 2);
        $csgo_total_time_played = floor(($csgocontent['playerstats']['stats'][2]['value']/60)/60);
        $csgo_total_planted_bombs = $csgocontent['playerstats']['stats'][3]['value'];
        $csgo_total_defused_bombs = $csgocontent['playerstats']['stats'][4]['value'];
        $csgo_total_wins = $csgocontent['playerstats']['stats'][5]['value'];
        $csgo_total_damage_done = $csgocontent['playerstats']['stats'][6]['value'];
        $csgo_total_money_earned = $csgocontent['playerstats']['stats'][7]['value'];
        $csgo_total_rescued_hostages = $csgocontent['playerstats']['stats'][8]['value'];
        $csgo_total_kills_knife = $csgocontent['playerstats']['stats'][9]['value'];
        $csgo_total_kills_headshot = $csgocontent['playerstats']['stats'][25]['value'];
        $csgo_total_rounds_played = $csgocontent['playerstats']['stats'][48]['value'];
        $csgo_total_mvps = $csgocontent['playerstats']['stats'][102]['value'];
        $dtp = $dtpcontent['response']['player_count'];
        $csgotp = $csgotpcontent['response']['player_count'];

    if (isset($dscontent['solo_competitive_rank'])) { 
           $ds_solo_competitive_rank = $dscontent['solo_competitive_rank'];
       } else {
           $ds_solo_competitive_rank = "N/A";
    }

    if (isset($dscontent['competitive_rank'])) { 
           $ds_competitive_rank = $dscontent['competitive_rank'];
       } else {
           $ds_competitive_rank = "N/A";
    }

        $ds_win = $dswinlosecontent['win'];
        $ds_lose = $dswinlosecontent['lose'];
        $ds_winloseprocent = round(($dswinlosecontent['win']/($dswinlosecontent['win']+$dswinlosecontent['lose']))*100, 2);
        $ds_kills = $dsrecordscontent['kills']['kills'];
        $ds_deaths = $dsrecordscontent['deaths']['deaths'];
        $ds_assists = $dsrecordscontent['assists']['assists'];
        $ds_kda = $dsrecordscontent['kda']['kda'];
        $ds_gold_per_min = $dsrecordscontent['gold_per_min']['gold_per_min'];
        $ds_xp_per_min = $dsrecordscontent['xp_per_min']['xp_per_min'];
        $ds_last_hits = $dsrecordscontent['last_hits']['last_hits'];
        $ds_denies = $dsrecordscontent['denies']['denies'];
?>
                <div class="player_dota">
                     <div class="info_dota">
                    Одиночный MMR: <?=$ds_solo_competitive_rank?><br>
                    Групповой MMR: <?=$ds_competitive_rank?><br>
                    Побед: <?=$ds_win?><br>
                    Поражений: <?=$ds_lose?><br>
                    Процент побед: <?=$ds_winloseprocent?>%<br>
                    Наибольшее число убийств: <?=$ds_kills?><br>
                    Наибольшее число смертей: <?=$ds_deaths?><br>
                    Наибольшее число помощи: <?=$ds_assists?><br>
                    Наибольшее соотношение KDA: <?=$ds_kda?><br>
                    Максимальное число золота в минуту: <?=$ds_gold_per_min?><br>
                    Максимальное число опыта в минуту: <?=$ds_xp_per_min?><br>
                    Максимальное число добиваний: <?=$ds_last_hits?><br>
                    Максимальное число денаев: <?=$ds_denies?><br>
                     </div>
                </div>
                <div class="player_steam">
                     <div class="info_steam">
                          <div class="name">
                               <a href="http://steamcommunity.com/profiles/<?=$steamid?>" alt="<?=$personaname?>"><?=mb_substr($personaname, '0', '15');?></a>
                          </div>
                                       <?=$steamid?><br>
                                       <?=$steamid32?><br>
                                       <img src='<?=$avatarfull?>'><br>
                                       <?=$profileurl?><br>
                                       <?=$gameextrainfo?><br>
                                       <?=$personastate?><br>
                                       <?php echo gmdate("d.m.Y H:i", $uptodate); ?><br>
                    Бан в сообществе: <?=$baninfocommunity?><br>
                    Статус VAC бана: <?=$baninfovac?>
                     </div>
                </div>
                <div class="player_csgo">
                    Всего убийств: <?=$csgo_total_kills?><br>
                                        Всего смертей: <?=$csgo_total_deaths?><br>
                    Соотношение убийств/смертей (KDA): <?=$csgo_total_kd?><br>
                                        Время в игре: <?=$csgo_total_time_played?> ч.<br>
                                        Заминировано бомб: <?=$csgo_total_planted_bombs?><br>
                                        Разминировано бомб: <?=$csgo_total_defused_bombs?><br>
                                        Всего сыграно раундов: <?=$csgo_total_rounds_played?><br>
                                        Раундов выиграно: <?=$csgo_total_wins?><br>
                                        Всего урона нанесено: <?=$csgo_total_damage_done?><br>
                                        Всего заработано денег: <?=$csgo_total_money_earned?>$<br>
                                        Заложников спасено: <?=$csgo_total_rescued_hostages?><br>
                                        Убийств с ножа: <?=$csgo_total_kills_knife?><br>
                                        Убийств в голову: <?=$csgo_total_kills_headshot?><br>
                                        Звезд лучшего игрока раунда (MVP): <?=$csgo_total_mvps?><br>
                </div> 

Библиотека ajax подключена:

<script src="/js/jquery-3.1.1.min.js"></script>
9
  • "А так не работает" - а что делает?
    – user176262
    1 фев 2017 в 14:46
  • Посмотри в console.log. Там запрос будет видно и результат
    – ilyaplot
    1 фев 2017 в 14:47
  • Ничего не происходит. Просто пустая страничка:
    – Xhonor
    1 фев 2017 в 14:54
  • cyberkld.ru/player/76561197962021169 Вот как оно работает.
    – Xhonor
    1 фев 2017 в 14:55
  • в ф12 xhr запросы отфильтруйте, и посмотрите что происходит. имхо указанный url кривой и возвращает 404.
    – teran
    1 фев 2017 в 14:56

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.