How do I load an external file and make sure that it runs first in JSFiddle?

后端 未结 4 2054
礼貌的吻别
礼貌的吻别 2021-02-12 14:24

I have a JsFiddle here, and added Microsoft AJAX to be loaded through external JS/resource section. How can I tell whether or not my JS code is run after the AJAX file has finis

相关标签:
4条回答
  • 2021-02-12 15:15

    @clayRay, You absolutely went thru a code surgery. Just resolved that by mentioning external source in plain html which in my case is

        <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    

    Using External Resources tab didn't help a bit...

    0 讨论(0)
  • 2021-02-12 15:19

    @Jpsy's approach no longer seems to work (see my comment under his answer).

    For me, adding the resource under External Resources also didn't work. (According to the Firefox Debugger, it couldn't find the resource).

    The only way I was able to get an external bit of JavaScript code (in my case jquery.backstretch.js) to work, was to use Google to find a Fiddle which used this resource (and worked), then Fork this Fiddle and copy/paste all my code into the HTML, CSS and JavaScript panels. Ugh!

    0 讨论(0)
  • 2021-02-12 15:20

    The External Resources tab of jsFiddle is currently somewhat tricky and unstable to use. The resources defined here are often not correctly included into the code. There seems to be an issue with the automatic recognition of JS and CSS resources. If this happens, the external resource is simply not added to the head section of the resulting code. You can check that by reviewing the source code of the Result frame of your jsFiddle. You will find that your MS AJAX resource is simply NOT mentioned in the resulting HTML code.

    The correct recognition can actually be forced by adding a dummy value to the resource's URL like this (see –>jsFiddle docs for more info):

    ...&dummy=.js
    

    Here is an example that shows how to add the external Google Maps API resource to a jsFiddle (mind the dummy parameter at the very end!):

    https://maps.googleapis.com/maps/api/js?sensor=false&dummy=.js
    

    Unfortunately this won't work for you as the MS AJAX URL will fail when additional parameters are appended.

    A solution (and currently the safest way to load external resources) is to avoid the External Resources tab altogether and load external code manually in the first line(s) of jsFiddle's HTML window like this:

    <script type='text/javascript' src="http://ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js"></script>
    

    Here is your jsFiddle modified to use that method: http://jsfiddle.net/rEzW5/12/

    It actually does not do a lot (I did not check what is wrong with the rest of your code), but at least it does not throw JavaScript errors anymore.

    0 讨论(0)
  • 2021-02-12 15:22

    Open "Add Resources" section and add the url of your external script...

    0 讨论(0)
提交回复
热议问题