Manual loading of api not working

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Manual loading of api not working

Postby Ninjaoninja2 » 19 Sep 2021, 23:26

Hi there,

For some reason when I manually load the api either from a web host, or locally, I keep getting this error.

Code: Select all

Uncaught ReferenceError: SFS2X is not defined.


I have triple-checked that the file is indeed being loaded. I don't know if this is a SmartFox issue or not because I know it's being loaded in the browser.

Here's how I'm calling the API in JavaScript, and just for good measure, the way I'm loading it in HTML.
JavaScript:

Code: Select all

var sfs;
var config = {};
    config.host = "127.0.0.1";
    config.port = 8080;
    config.debug = true;
    config.useSSL = false;
     sfs = new SFS2X.SmartFox(config);


HTML:

Code: Select all

<script type='text/javascript' src='libs/sfs2x-api-1.7.18.js'></script>


I'm also seeing this error with the API, not sure if this is causing SFS2X to appear undefined.

Code: Select all

Uncaught SyntaxError: no line break is allowed between 'throw' and its expression sfs2x-api-1.7.18.js:4301:16


UPDATE: I have double-checked if I use 1.7.18 with webpack if it does the same thing, it does not. Unfortunately, this particular project requires the api be loaded from an HTML script tag as webpack is not playing nicely with other files within the project.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Manual loading of api not working

Postby Bax » 20 Sep 2021, 10:03

Are you sure the API JavaScript file is not corrupted? Because the loading approach you use is the same we use in our examples, and they work as expected. Also, the error you reported doesn't show up in our examples.
Paolo Bax
The SmartFoxServer Team
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Manual loading of api not working

Postby Ninjaoninja2 » 20 Sep 2021, 16:59

Bax wrote:Are you sure the API JavaScript file is not corrupted? Because the loading approach you use is the same we use in our examples, and they work as expected. Also, the error you reported doesn't show up in our examples.


It could be. Let me try downloading the api again in a fresh new place, and I will update you on how it goes.
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Manual loading of api not working

Postby Ninjaoninja2 » 20 Sep 2021, 17:05

Bax wrote:Are you sure the API JavaScript file is not corrupted? Because the loading approach you use is the same we use in our examples, and they work as expected. Also, the error you reported doesn't show up in our examples.

Yup, it was a corrupt api file. Thanks! :shock: :lol:

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 22 guests