问题
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...
回答1:
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');
});
回答2:
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 :)
来源:https://stackoverflow.com/questions/9833411/does-jquerys-getscript-behave-differently-in-firefox-its-not-executing-the