kongregate 未定义错误 javascript

kongregate not defined error javascript

我已经按照文档中的说明在头部包含了所需的文件

<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>

然后在我的脚本上方我包含了应该定义变量的脚本

<script>
    kongregateAPI.loadAPI(function(){
        window.kongregate = kongregateAPI.getAPI();
    });
</script>

但是在控制台中我仍然收到这个错误 Uncaught ReferenceError: kongregate is not defined

你说:

And then right above my scripts i included

这是否意味着您的代码看起来像这样?

<script>
    kongregateAPI.loadAPI(function(){
        window.kongregate = kongregateAPI.getAPI();
    });
</script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>

如果是这样,您应该在加载 api js 文件后调用 kongregateAPI 函数:

<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js'></script>
<script src='https://cdn1.kongregate.com/javascripts/kongregate_api.js'></script>
<script>
    kongregateAPI.loadAPI(function(){
        window.kongregate = kongregateAPI.getAPI();
    });
</script>

我试过了,一切正常。