Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
57
rated 0 times [  60] [ 3]  / answers: 1 / hits: 160671  / 12 Years ago, fri, august 3, 2012, 12:00:00

I can't seem to figure out the Chrome debugging tool.



I have chrome version 21.0.1180.60 m.



Steps I took:




  1. I pressed ctrl-shift-i to bring up the console.

  2. Clicked on Sources then select the relevant javascript file that I want to debug.

  3. I set breakpoints where I want the code to stop by putting a blue tag on the gutter next to the line on the left.

  4. I clicked on the button on my webpage (which is a php rendered page) that initiates the javascript code.

  5. The code ran successfully without stopping.



I also noticed that the Watch Expressions don't work either. It keeps telling me that the variable that I want to watch is undefined.



Further testing found that it's my code that's causing the breakpoint to fail. It seems that it fails on the $(#frmVerification).submit(function(){ line. It doesn't step into the breakpoints inside that function().



Below is the:



//function to check name and comment field 
var test = this is a test;
var test2 = this is another test;

function validateLogin(){
//if(userEmail.attr(value) && userPass.attr(value))
return true;
//else
//return false;
}

//onclick on different buttons, do different things.
function ajaxRequest(){

}
$(document).ready(function(){
//When form submitted
$(#frmVerification).submit(function(){
var username = $(#username);
var token = $(#token);
var action = $(#action);
var requester = $(#requester);
if(validateLogin()){
$.ajax({
type: post,
url: verification.php,
data: username=+username.html()+&token=+token.val()+&action=+action.val()+&requester=+requester.val(),
success: function(data) {
try{
var jsonObj = $.parseJSON(data); //convert data into json object, throws exception if data is not json compatible
if(jsonObj.length > 0){//if there is any error output all data
var htmUl = $('<ul></ul>');
$.each(jsonObj, function(){
htmUl.append('<li>' + this + '</li>');
});
$(#errOut).html(htmUl);
}else{
alert(Your account is now activated, thank you. If you have already logged in, press OK to go to the home page. If not, you must log in first.);
window.location.replace(home.php);
}
}
catch(e){//if error output error to errOut]
$(#errOut).html(PHP module returned non JSON object: <p>+data+</p>);
}
}
});
}
else alert(Please fill UserName & Password!);
return false;
});
});

More From » debugging

 Answers
141

I'm not sure why your breakpoints aren't hitting, but one sure-fire way to step into your code is to type



debugger;


where you want the code to halt, and then run again with the chrome developer tools window open.






Just one small thing to be aware of, be sure to clean up after you done and remove the debugger lines. If you ever run JavaScript files through YUI compressor, the existence of a debugger; line will cause it to error out.


[#83884] Thursday, August 2, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lindsay

Total Points: 402
Total Questions: 109
Total Answers: 109

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;