kongregate未定义错误javascript

时间:2016-06-24 16:32:54

标签: javascript jquery ajax kongregate

我已将所需文件包含在头文件中,如文档中所述

<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

1 个答案:

答案 0 :(得分:0)

你说:

  

然后在我的脚本正上方

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

<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>

我已经尝试过,一切正常。