Does jQuery's $.getScript behave differently in Firefox ? It's not executing the script after loading it, Chrome is doing fine

1.9k Views Asked by At

The following code

$.getScript("/js/dygraph-combined.js")
  .done(function(script, textStatus) {
    console.log(Dygraph);
  })
  .fail(function(jqxhr, settings, exception) {
    console.error('it failed to load');
  });

yields

Dygraph is not defined

in Firefox 11.0, and

[Dygraph 1.2]

on Chrome 17.0.963.83.

So it seems that the script loads on both browsers but doesn't get executed in Firefox 11... Why would that be ? How do I get this behaving like it should ?

This script is Dygraph and from it's website it works on Firefox, but my graphs only work on Chrome possibly because jQuery's $.getScript might be behaving differently...

2

There are 2 best solutions below

6
On

Try doing:

    $.getScript("http://dygraphs.com/dygraph-combined.js", function(script, textStatus) {
        setTimeout(function(){console.log(Dygraph);}, 0);
    }).fail(function(jqxhr, settings, exception) {
        console.error('it failed to load');
    });
0
On

I had the same issue and in the dygraph-combined.js it said "This is not the file you are looking for". but the jedi mind trick didn't work on me, I followed the link provided.
http://dygraphs.com/dygraph-combined.js

Now it works :)