1

这是我的javascript。在我的合作伙伴执行 Git Pull 之前,它运行良好。单击提示会加载精美的框。负载现在不起作用。

Game = {

loadLevel: function(levelNum) {
    $("#level").load("/level/" + levelNum + "/", function() {

        // disable all hints except the first
        $("#level .hint:not(:first)").prop('disabled', true);

        // clicking a hint displays the hint
        $("#level .hint").each(function(index, el) {
            $(el).fancybox({
                href : $(el).attr("data-url"),
                type : 'ajax',
            });
        });

        // enable next hint when clicking on a hint
        $("#level .hint").on("click", function() {
            $(this).next().prop('disabled', false);
        });

        // if answer is correct load next level
        $("#answer").on("click", function() {
            $.get("/answer/" + levelNum + "/", {
                guess : $('.guess').val()
            }, function(answer) {
                console.log(answer);
                if (answer) {
                    Game.loadLevel(levelNum+1);
                }
            });
        });
    });
},

}
4

2 回答 2

2

从错误消息中,听起来您的合作伙伴的代码在某处有一个无限循环的递归调用,或者调用了太多深入的函数。

于 2013-02-20T12:43:13.723 回答
1

试试这个:

 loadLevel: function(levelNum) {
   if (levelNum > 5) return;
   $("#level").load("/level/" + levelNum + "/", function() {

我认为问题可能出在此处-但可能出在您未显示的代码中:

               Game.loadLevel(levelNum+1);

这将递归,但没有办法阻止它。

于 2013-02-20T13:06:06.460 回答