打开ID&蒸汽从负载中止

时间:2014-06-30 20:44:26

标签: javascript php jquery ajax

因为我将Steam登录到网站,所以我遇到了这个问题。基本上,因为steam api有时需要大约40秒才能加载数据,所以我在加载时创建了一个javascript函数,以加快页面加载速度。加载页面后加载此函数,因此steam api在后台运行。但是,如果用户离开/刷新页面,此功能正常工作[代码1],新页面将等待之前的加载功能。

PS:所有连接(数据库,steamapi ..)都是由connect.php制作的,如下所示[代码3]。这个页面加载有两种方式:在页面加载之前使用php include()函数(通过这种方式,我可以包含任何所需的文件,如数据库信息,数据库连接)[代码4]。第二种方式是下面的javascript函数[代码2]。

PS 2:您可以通过刷新页面在http://portal.sf-gaming.co.uk/portal/上进行实时测试,而加载...仍会显示在版权栏旁边。

[代码1 - Steam Web API脚本(userInfo.php)]

$api_key = "XXXXXXXXXXXXXXX"; // Insert API Key here!

    $urla = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $api_key; 
    $urlb = "&steamids=";
    $urlc = $urla . $urlb;
    $url = $urlc . $_SESSION['steamid'];
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($ch);
    curl_close($ch);
    $content = json_decode($content, true);

    $_SESSION['sp_steamid'] = $content['response']['players'][0]['steamid'];
    $_SESSION['sp_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
    $_SESSION['sp_profilestate'] = $content['response']['players'][0]['profilestate'];
    $_SESSION['sp_personaname'] = $content['response']['players'][0]['personaname'];
    $_SESSION['sp_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
    $_SESSION['sp_profileurl'] = $content['response']['players'][0]['profileurl'];
    $_SESSION['sp_avatar'] = $content['response']['players'][0]['avatar'];
    $_SESSION['sp_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
    $_SESSION['sp_avatarfull'] = $content['response']['players'][0]['avatarfull'];
    $_SESSION['sp_personastate'] = $content['response']['players'][0]['personastate'];
    $_SESSION['sp_realname'] = $content['response']['players'][0]['realname'];
    $_SESSION['sp_primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
    $_SESSION['sp_timecreated'] = $content['response']['players'][0]['timecreated'];
    $_SESSION['sp_loccountry'] = $content['response']['players'][0]['loccountrycode'];

    $_SESSION['sp_steamid32'] = GetSteam32ID($_SESSION['steamid']);

    date_default_timezone_set("GMT");
    $_SESSION['sp_currenttime'] = date("Y-m-d H:i:s", time());
    $_SESSION['sp_clientip'] = $_SERVER['REMOTE_ADDR']." | ".$_SERVER['HTTP_X_FORWARDED_FOR'];

[代码2 - Javascript功能]

<script type="text/javascript">
function loaddata()
{
    document.getElementById('page_loading').style.display = "block";
    $.post("<? echo $js_url."connect.php?refresh_steamdata=true&refresh_databasedata=true".$js_url_par; ?>",{
    },
    function(data)
    {
            document.getElementById('page_loading').style.display = "none";
            <? if($curpage == "My Account") { ?>
            document.getElementById("profileloadingBlanket").style.display = "none";
            document.getElementById("profileloadingDiv").style.display = "none";
            $("#profile_Area").load("account.php #profile_Area").fadeIn();
            <? } ?>
    });
}

loaddata();
</script>

[代码3 - 由函数加载的connect.php]

// Get Steam Data
if(isset($_SESSION['steamid']) and !isset($_SESSION['sp_steamid']) or $refreshall == true or $refresh_steamdata == true)
{
    include ("steamauth/userInfo.php");
    //echo "Executed userInfo.php and steamauth/userInfoWRITE.php \n";
}

// Get Database Data
if(!isset($_SESSION['mi_SteamID']) and isset($_SESSION['steamid']) or $refreshall == true or $refresh_databasedata == true)
{
    include("database_info.php");
    //echo "Executed database_info.php \n";
}

[代码4 - include()函数在每个页面中运行,如javascript函数。]

$refreshall= $_GET["refreshdata"];
include("../connections/connect.php");

[编辑1] 我脑子里有一些修复: 1.在卸载页面之前,可以通过某种方式中止javascript加载功能。 2.在卸载页面之前,php函数可能会以某种方式破坏。启动该代码会停止加载json文件(工具加载40秒)。

0 个答案:

没有答案