0

I am using MVC and jquery to pull in a function from the server (as a partial view which I generate on the fly and append to the body of the html) and execute it. This works fine, I can view it in fiddler, but debugging is terrible. I pull in the method using something like:

    $("#makeGrid").click(function (e) {
        $.get('/gridder/basicgrid', callbackFn);
        function callbackFn(data) {
            //Append markup to dom
            $('body').append(data);
            // call the js function from the partialview here 
            generateGrid();
        }
    });

Whether this is best practice or not I'm not sure, but if I 'view source' after the ajax command, the code isn't visible, and using the debugger; command doesn't seem to work. Eg:

    function generateGrid() {
        alert("start");
        debugger;
        alert("end");
    }

Creates the two alerts but doesn't bring up the debugger even though firebug is active. This discussion raises a similar issue. Some worked around it by using debugger twice (this bug meant to be gone now) or opening firebug in a new window (no luck). Even eval('debugger;'); was suggested by someone in another thread but no good!

Any suggestions? (including using a tool other than firebug if needed, but I want to debug, not view fiddler-style)

Community
  • 1
  • 1
Glinkot
  • 2,924
  • 10
  • 42
  • 67
  • 1
    `view source` will never display content loaded in via ajax. You need to inspect the DOM using something like Firebug, or a broswers built in DOM inspector – Tim B James Oct 05 '11 at 08:35
  • Can you not set a breakpoint in Firebug rather than using the `debugger` statement? – Paul Grime Oct 05 '11 at 11:08
  • Thanks guys - re: DOM inspection, I haven't yet been able to find the element that contains the code. It does execute (my alerts come up), but all attempts to throw an exception or invoke the debugger don't result in anything. And paul, I can't see the code so can't add the breakpoint unfortunately. – Glinkot Oct 05 '11 at 22:46
  • Did you try it in Chrome (with developer tools opened and debugger statement)? – Martin Gamulin Oct 07 '11 at 00:45
  • Hi Martin, yes, I did try chrome with the same results. Not sure why. Perhaps it was because I was bringing in a standard partialview with a – Glinkot Oct 07 '11 at 22:15

1 Answers1

0

Doesn't look like a conclusive answer is coming on this one. For others' reference, I ended up getting debugging going in VS2010 itself, as follows:

a) Must use IE as VS default browser. Firefox doesn't like playing. If you're using MVC, the default browser selector doesn't come up against views etc like it does in webforms. A quick solution is to create an empty .html page in the root and right click that bastard to get 'browse with...' and select the desired default browser. Tada.

b) Next, in IE's advanced options, make sure you untick the 'disable javascript debugging' options.

c) Now, you can use the debugger; command in your script within the view to break execution of your dynamically generated script. It will go back to VS and highlight the line. Because it's generated it says [dynamic script] at the top. Breakpoints still don't seem to work annoyingly.

d) In IE, the js errors also are reported in the console. It will give you a line number and column, highlighting your file. If you have sent a dynamic partial view though, it highlights these coordinates in your original page file, which is not applicable. Rather, go to the equivalent coordinates in the "script block [dynamic]" tab of VS.

In truth this is probably more useful for MVC development than what Firebug would have offered.

Cheers

Glinkot
  • 2,924
  • 10
  • 42
  • 67