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)
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