0

I'm using VS2010. I have javascript visible and I placed a breakpoint in a function like below:

function doShow() { 
//    $('#save').click(function () {

        var product = { ProductName: $('!Response[0]').val(),
                  UnitPrice: $('#Price').val(),

              alert(product);

I placed a breakpoint on the line starting with var and the line starting with Alert. VS2010 accepted the breakpoint and put a small red circle with white center there.

When I run the script the alert shows but it never stops at the breakpoint.

Any ideas what I am doing wrong. note my code is running local

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Melova1985
  • 387
  • 2
  • 4
  • 5

3 Answers3

3

Install the Firebug add-on for Firefox. It will allow you to do all kinds of Javascript (and other) debugging, inside the browser.

AndrewR
  • 6,668
  • 1
  • 24
  • 38
1

A technique you can use to debug JavaScript using Visual Studio is to add this code to your JavaScript and then run your page in IE.

debugger;

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
  • I did this but nothing happens? Are there some other steps and where should I put this line? – Melova1985 Apr 22 '11 at 08:49
  • 1
    Make sure "Disable Script Debugging" is turned off in "Internet Options" --> "Advanced" tab of Internet Explorer. If that's not enough, make sure you're in debug mode and running your app through Visual Studio. If that still doesn't work, set IE as your default browser. More info here...although this article is about IE6, it also applies to other IE versions: http://sixrevisions.com/javascript/javascript-debugging-techniques-in-ie-6/ – Johnny Oshika Apr 22 '11 at 16:00
1

The best way that I've found to debug JavaScript is to use the built in developer tools found in IE9 and Chrome (or Firebug in Firefox as mentioned in this discussion). Since JavaScript is a client-side language, I'm not sure that Visual Studio will have access.

Resources on using JavaScript Debuggers:

Edit: As indicated below, you can use Visual Studio with IE.

Community
  • 1
  • 1