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

这一生的挚爱 提交于 2019-12-13 00:18:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!