0

I have seen a code for a countdown timer, that goes as follows:

jQuery(function() {

    var days, goLive, hours, intervalId, minutes, seconds;
    goLive = function() {
        $(".countdown_timer").hide();
        return $(".live_now").show();
    };
    days = void 0;
    hours = void 0;
    minutes = void 0;
    seconds = void 0;
    intervalId = void 0;
    return $.ajax({
        url: "http://(mywebdomain.com)/json/next",
        dataType: "jsonp",
        success: function(data) {
            var seconds_till;
            $("#churchonline_counter").show();
            if (typeof data.current_timestamp !== "undefined") {
                return goLive();
            } else if (typeof data.next_timestamp !== "undefined") {
                seconds_till = data.next_timestamp - (new Date().getTime() / 1000);
                hours = Math.floor((seconds_till % 86400) / 3600);
                minutes = Math.floor((seconds_till % 3600) / 60);
                seconds = Math.floor(seconds_till % 60);
                return intervalId = setInterval(function() {
                    if (--seconds < 0) {
                        seconds = 59;
                        if (--minutes < 0) {
                            minutes = 59;
                            if (--hours < 0) {
                                hours = 23;
                            }
                        }
                    }
                    $(".counter_h").html((hours.toString().length < 2 ? "0" + hours : hours));
                    $(".counter_m").html((minutes.toString().length < 2 ? "0" + minutes : minutes));
                    $(".counter_s").html((seconds.toString().length < 2 ? "0" + seconds : seconds));
                    if (seconds === 0 && minutes === 0 && hours === 0) {
                        goLive();
                        return clearInterval(intervalId);
                    }
                }, 1000);
            }
        }
    });
});

But I do not know how to create the JSON file on my web server so that it will read the data properly? I have tried uploading a file called "next" as a simple text file on my server using Filezilla that looked as follows:

({"next_timestamp":1356751800,"next_duration":3600,"next_title":"Title","next_description":"Description"})

But I think I am missing something on this Json uploaded file? I know my code works in the javascript, but the Json file I am not sure what to do with. How do I name or alter the Json file to properly have the javascript parse it?

4

1 回答 1

0

这个倒计时脚本是专门为 Churchonlineplatform.org 用户编写的,作为该站点的用户,我可以告诉你,这行内容如下:

url: "http://(mywebdomain.com)/json/next",

只是一个样本,实际上应该是

url: "http://mywebdomain.com/json/next",

希望这可以帮助

于 2013-02-04T16:04:30.920 回答