1

https://gist.github.com/dukevis/9039575

I have code that, when I view it through a localhost while I'm editing, doesn't have any errors and shows up fine. However, when I uploaded it to gist and view it through the bl.ocks extension, the image doesn't load and results in various errors, including "undefined variable" (line 95). I'm wondering if there's a general reason why new errors would arise when uploaded to the web that weren't an issue when locally hosted, or if something specific is wrong with my code. Thanks!

1 Answers1

0

You have to execute that code when all the library and assets more in general are loaded.

When you are working with localhost everything is loaded together (almost) and you don't see any asynchronous issue: if you don't have to wait particular assets a common trick is to write your js code at the bottom part of the page, so that all the DOM is loaded before executing it.

If you want to wait all the assets instead, just use the jquery $(document).ready(...) to wrap your function - or it's JS complicated equivalent - or, if you need to wait also fonts to load simply window.onload = function(){...} - you can use this also if you don't have any fonts, it's just triggered later than the previous one.

Community
  • 1
  • 1
MarcoL
  • 9,829
  • 3
  • 37
  • 50
  • Thank you! That's useful information, however I'm not sure how to apply it to my specific situation. My issue appear to be with `teams.sort(function(a,b){ return parseFloat(b.values[51].wins)-parseFloat(a.values[51].wins); });` I'm trying to sort the lines by their lastest total win count, however when uploaded to the web it says that 'wins' is undefined. – Erica Fischer-Colbrie Mar 13 '14 at 00:10
  • Your cdv has 49 lines but you are using the line 52 (you write 51 but it starts from 0...) in your sorting code. – MarcoL Mar 13 '14 at 07:22