Search code examples
javascriptjqueryajaxkongregate

kongregate not defined error javascript


I have included the required files in the head as it says in the docs

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

And then right above my scripts i included the script that supposed to define the variable

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

But in the console I am still getting this error Uncaught ReferenceError: kongregate is not defined


Solution

  • You said:

    And then right above my scripts i included

    Does it mean that your code looks like this?

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

    If so, you should call kongregateAPI functions after you loaded api js file:

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

    I've tried it, everything works fine.