Giter Club home page Giter Club logo

Comments (5)

brianbaker avatar brianbaker commented on July 16, 2024

$.getScript is just shorthand for $.ajax. $.getScript(url, callback) becomes $.get(url, undefined, callback, 'script') which in turn becomes jQuery.ajax({url: url, type: 'get', dataType: 'script', data: undefined, success: callback })

What you may be noticing is jQuery switching to XHR rather than using a <script> tag to load the script. Even though the 'script' dataType is being used, jQuery will still check to see if its really going to be a cross domain request. Only if its a cross domain request does it load via a <script> tag.

I've also noticed that sometimes the script isn't available because jQuery removes the tag from the DOM once the script has been loaded.

Sometimes I'll just insert a debugger; statement in my code to set a breakpoint if I either can't find the script or if there are so many scripts I don't feel like looking through them.

from f2.

ilinkuo avatar ilinkuo commented on July 16, 2024

@brianbaker I think that your explanation is what matches the second link I gave: http://stackoverflow.com/questions/690781/debugging-scripts-added-via-jquery-getscript-function. That also gives a workaround to force the use of script tag even in the case of local domain. The current jQuery behavior seems to me to be the wrong default behavior -- script should always be preferred to XHR + eval -- but I'd guess this is to work around IE issues because XHR lifecycle notification is better supported than script lifecycle notification.

I'll try the debugger suggestion, but from what I've read, it won't actually work. I'd guess that the debugger simply does not have access to the code, so even if it stops, I can't see or inspect the code. I'll report back once I try it.

from f2.

brianbaker avatar brianbaker commented on July 16, 2024

Hi @ilinkuo, any update on how using debugger went? Were you able to figure out any consistent steps to reproduce the issue?

from f2.

ilinkuo avatar ilinkuo commented on July 16, 2024

@brianbaker The issue rendered moot when a url was provided so I was no longer hitting localhost -- this problem only occurs when the domains match. But I'm interested in the answer so I'll get back to this either today or tomorrow (4/30).

from f2.

ilinkuo avatar ilinkuo commented on July 16, 2024

This can be closed. The problem exists only for locally loaded scripts and can be worked around in FFox but not Chrome.

  • Scripts loaded by F2 locally using jQuery's ajax do not appear normally in the debuggers for Chrome or FFox (IE not tested). The requests appear in the Chrome Network and FBug Net tabs, but do not appear in the Chrome Sources or FBug Script tab.
  • Adding debugger; successfully stops the code displaying the source in FBug but not in Chrome.
  • Apparently, the code is available to FBug, but not as the original file but rather as an eval'ed file. In my case, I expected FBug to show the script at js/streamingNews/prettydate.js but in fact it it showed under f2.debug.js/eval/seq/15.
  • The snippet from http://stackoverflow.com/a/691661/1932390 replacing jQuery getScript did not work for me but I didn't spend much time getting it to work.

from f2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.