问题
I am not able to use the breakpoint in Studio with Javascript. I'm able to debug if I use the debugger;
I've seen this Breakpoint not hooked up when debugging in VS.Net 2005 question already. I tried the answer and it didn't work.
Looking in the Modules window, V.Mvc.Jobtrakt.PDB is loaded properly, but it points to a temp folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\dbc0c0c5\f64a99b3\assembly\dl3\9de055b3\eb1303b1_9760c901\V.Mvc.Jobtrak.pdb: Symbols loaded.
I would have thought that it would point to: \JobTrak\Website\V.Mvc.Jobtrak\V.Mvc.Jobtrak\obj\Debug ( this is within the project directory)
But regardless of the location I closed VS 2008 and then blew away the temp folder (listed above), the bin and obj folders.
Opened VS 2008 and did a clean. I set a break point in the js and it seemed like it would work now ( The breakpoint was filled in) Started to debug and it never breaks on the breakpoint. Look at the break point and it now is a red circle with a red dot and a warning indicator. Hovering over the breakpoint gives me this useful information: The breakpoint will not currently be hit. The location could not be mapped to a client side script. See help for ASPX Breakpoint mapping. I am not being redirected, the breakpoint is with in a function. blah blah blah this should be working.
So I was wondering if anyone has any ideas? Is anyone able to set breakpoints in VS2008 and have them work?
回答1:
try typing "debugger" in the source where you want to break
回答2:
Make sure you are attached to the correct process. For example, once you have your page loaded in IE,
- Switch to Visual Studio and go to the Debug menu.
- Choose "Attach to Process"
- Find iexplore in the list and select it.
- Click the "Select..." button.
- In the dialog, choose "Debug these code types:" and select only "Script".
- Click "OK"
- Click "Attach"
See if that helps get you debugging javascript.
回答3:
this happened to me also. The breakpoints stopped to work in some functions. In my case, the problem was that I used <%=..%> inside the script. As far as I could figure out reading MSDN, this happens because Visual Studio maps the breakpoint lines from the .ASPX to the resulting HTML based on line content, so when you put a <%=..> your resulting script will be different from the one in the .ASPX file.
回答4:
You shouldn't have to put debugger in the javascript. I had this happen and the reason was there was an error in the script in a try catch block in terms of syntax. As soon as I fixed the syntax, breakpoints mapped correctly again.
回答5:
Greg answered the question, however just to add some more value to answer -
Put debugger in the java script code.
As well make sure you have debugger enabled in the internet explorer > Tools > Internet Options > Advance
the check boxes for disabled debugging should not be checked.
回答6:
In my case, was due I was using
$.ajax({ type: "GET",
instead $.ajax({ type: "POST",...
回答7:
Just type alert function in script for each line or any line, if the alert is not triggered then we can identify the line where its through the error
<script type="text/javascript">
$(function() {
//event handler to the checkbox selection change event
$("input[type=checkbox]").change(function() {
//variables to store the total price of selected rows
//and to hold the reference to the current checkbox control
var totalPrice = 0, ctlPrice;
//iterate through all the rows of the gridview
$('#Grid2 tr').each(function() {
//if the checkbox in that rows is checked, add price to our total proce
alert("Hi")
if ($(this).find('input:checkbox').attr("checked")) {
ctlPrice = $(this).find('[id$= lblPackAmount]');
//since it is a currency column, we need to remove the $ sign and then convert it
//to a number before adding it to the total
totalPrice += parseFloat(ctlPrice.text().replace(/[^\d\.]/g, ''));
}
});
//finally set the total price (rounded to 2 decimals) to the total paragraph control.
//alert(totalPrice);
$('#lblAmount').text(totalPrice);
});
});
</script>
来源:https://stackoverflow.com/questions/376384/using-breakpoints-to-debug-javascript-in-ie-and-vs2008