自动更新没有重复内容

时间:2015-02-27 23:53:36

标签: php jquery ajax wordpress

我创建了一个基本输出匹配结果列表的短代码。这些匹配结果由JSON脚本解析,该脚本连接到服务器上的cron作业,每5分钟更新一次。而不是人们刷新浏览器本身我想知道我怎么能够使用AJAX,Jquery自动更新这个并且不重复匹配?

短代码如下:

[resultpage]

短代码功能:

function resultpage() {



    $output = '';



    $output .= '<div id="content">';
        $output .= '<div id="part-1">';

        $output .= getgames("lol");


        $output .= '</div>';
       $output .= ' <div id="part-2">';
       $output .= getgames("counterstrike");
       $output .= ' </div>';
       $output .= ' <div id="part-3">';
       $output .= getgames("dota2");
       $output .= ' </div>';
       $output .= ' <div id="part-4">';
       $output .= getgames("hearthstone");
       $output .= ' </div>';
    $output .= '</div>';




return $output;
}

getGames函数

function getgames($thegame) {
$json = file_get_contents('JSON URL');
$obj = json_decode($json);
$livegames = $obj->live;  


$output = '';

foreach($livegames as $live){



        if ($live->game == $thegame) {
            $teamarray = returnteam($live->{'team 1'}->name, $live->{'team 2'}->name);

        if ($live->{'team 1'}->score == "") {
            $score1 = '0';
        }else {
            $score1 = $live->{'team 1'}->score;
        }
        if ($live->{'team 2'}->score == "") {
            $score2 = '0';
        } else {
            $score2 = $live->{'team 2'}->score;
        }



        $output .= '<div class="result-in-month">';

        $output .= '<div class="result-date">';
        $output .= $live->{'live in'};
        $output .= '</div>';
                $output .= '<div class="result-match-team-wrapper">';
                    $output .= '<span class="result-match-team left">';
                        $output .= $teamarray[0];

                    $output .= '</span>';
                    $output .= '<span class="result-match-versus">';
                        $output .= '<span class="result-match-score">'. $score1 .'</span><span class="result-match-separator">-</span><span class="result-match-score">'. $score2 .'</span>';
                    $output .= '</span>';
                    $output .= '<span class="result-match-team right">';
                    $output .= $teamarray[1];

                    $output .= '</span>';
                $output .= '</div>';
                $output .= '<div class="result-stream">';
                $output .= '<a href="'. $live->{'streams'}[0] .'">';
                $output .= 'Stream';
                $output .= '</a>';
                $output .= '</div>';

            $output .= '<div class="clear"></div>';

        $output .= '</div>';

    }
    }
}

示例数据

{
    "live": [
    {
        "match_id": "65551",
        "has_vods": false,
        "game": "hearthstone",
        "team 1": {
            "score": "",
            "name": "ViCi Gaming",
            "bet": "39%"
        },
        "team 2": {
            "score": "",
            "name": "ZhanQi TV",
            "bet": "61%"
        },
        "live in": "Live",
        "title": "ViCi Gaming... 39% vs 61% ZhanQi TV",
        "url": "",
        "tounament": "http://www.gosugamers.net/",
        "simple_title": "ViCi Gaming... vs ZhanQi TV",
        "streams": [
            "http://www.twitch.tv/widgets/live_embed_player.swf?channel=Curemew"
        ]
    },
    {
        "match_id": "64907",
        "has_vods": false,
        "game": "dota2",
        "team 1": {
            "score": "",
            "name": "Summoner's Rift",
            "bet": "19%"
        },
        "team 2": {
            "score": "",
            "name": "Thundercats!",
            "bet": "12%"
        },
        "live in": "Live",
        "title": "Summoner's Rift 19% vs 12% Thundercats!",
        "url": "",
        "tounament": "http://www.gosugamers.net/",
        "simple_title": "Summoner's Rift vs Thundercats!",
        "streams": [
            "http://www.majorleaguegaming.com/player/embed/joinDOTA?autoplay=0"
        ]
    }
    ]
}

0 个答案:

没有答案