简体   繁体   中英

no line breaks in firebug when dynamically loading script with jQuery

When I dynamically load a script with jquery

...
options = {
  dataType: "script",
  cache: true,
  url: "...appContr.js"
}
return jQuery.ajax(options);    
...

and I debug the script with firebug, this script has the name "1" and everything is in one line (or in a few lines). I cannot use this for debugging.

I use Firefox 10.0.2 and Firebug 1.9.1.

When I use LAB.js

$LAB.script("...appContr.js").wait(function() {
      ...
    });         

or require.js

The file has its line breaks and the name of the script is "appContr".

How can I change the jQuery command in order to get the same result?

Thanks a lot in advance

EDIT:

Thank you, Headshota, for your answer, but this does not help.
Besides, getscript does not cache the contents, and this is important for me.

EDIT:

Thank you, Marlin, for your answer:

The whole thing works without firebug enhancements when I load the script with lab.js or require.js, the problem is only with jquery script loading.

In firebug I have the tabs console, html, css, script, dom and network. If I go - after jquery script loading - to script and view the script, there are no line breaks in the code.
But when I go to the "tab" console, I have one entry for the get request. When I click "answer" in this get request, the script contains the line breaks. But this does not help me because in the "script" tag the line breaks are missing.

dataType: script tells jQuery.ajax() to interpret the response as JavaScript and evaluate it.

"script": Evaluates the response as JavaScript and returns it as plain text.

An evaluated code basically has no file, line number and probably no white space. If you try to debug it in FireBug, it will probably tell you that it is "eval()ed" code.

JavaScript loaders such as LABjs work by injecting a <script src> tag in your document; it is easier for FireBug to debug because the JavaScript filename, file content and line numbers are all available.

I am not certain how to get the script's name right in firebug, but as to your other dilemmas there are a couple Firebug extensions you should consider

JS Deminifier 1.0.7 by Ben Murphy: This will expand your javascript into very readable code (but can lead to breaks if the javascript has been incredibly minified but that doesnt sound like it'll happen in your case). Just make sure that you turn on your addon bar which shows up below firebug and JSD is set to on (in the bottom left).

Another Good Option for Javascript debugging in Firebug...

FireRainbow 1.5 by BinaryAge: This provides javascript viewed in firebug with very helpful syntax highlighting.

Hope these tools alleviate your issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM