0

I have a .js file imported in another .js file like this:

$.getScript("/js/...../myFile.js", function() {
    });

All the code is full loaded becasue I can use functions inside the file. But when I'm trying to debug it by firebug or developers tools of IE8, the js is not included in the page, so I can't debug this because I can't select the .js and set my breakpoints. How can I "really" load the file so I can debug it? Thanks

Fseee
  • 2,476
  • 9
  • 40
  • 63
  • 1
    If it's loaded, it's debuggable? Are you sure it's not returning a 404 for the resource. Use the net/network tab in Firebug and check it's being returned – SpaceBison Nov 20 '12 at 16:53
  • If you can call the functions in the file, then it is loaded. I think you need to manually add the file, for debugging. Have you tried Chrome Dev tools? – nekman Nov 20 '12 at 16:54
  • 1
    If your website is in development, perhaps you should manually add the script to your website to debug it and set breakpoints, and then in production you can fetch it at will. Or perhaps you can add a script element to your DOM and point the src to your url. This should work. – danronmoon Nov 20 '12 at 16:56
  • @SpaceBison yes it's loaded correctly checking net tab of firebug – Fseee Nov 20 '12 at 16:58
  • Possible duplicate of http://stackoverflow.com/questions/690781/debugging-scripts-added-via-jquery-getscript-function?answertab=votes#tab-top – crowjonah Nov 20 '12 at 17:00

2 Answers2

0

Chrome has a feature where you can specify a parser attribute and make the piece of dynamic JS appear as a file which can then be browsed to and break points set.

In chrome at scripts tab you can enable 'pause on all exceptions'

enter image description here

And then put somewhere in your code line try{throw ''} catch(e){}. Chrome will stop execution when it reaches this line.

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
  • Whish is this feature: 'Chrome has a feature where you can specify a parser attribute and make the piece of dynamic JS appear as a file which can then be browsed to and break points set'? – JotaBe Jan 28 '14 at 15:19
  • Its easier to just use: "debugger": http://stackoverflow.com/questions/3425260/how-to-cause-a-debug-break-in-firebug – lepe Feb 17 '14 at 07:20
0

According to this previous answer:

jQuery.ajax({
        crossDomain: true,
        dataType: "script",
        url: "js/.../myscript.js",
        success: function(){
            _success(_slot)
        },
        error: function(){
            _fail(_slot);
        }
    });

full working

Community
  • 1
  • 1
Fseee
  • 2,476
  • 9
  • 40
  • 63