Chrome javascript 调试器断点不执行任何操作? [英] Chrome javascript debugger breakpoints don't do anything?

查看:25
本文介绍了Chrome javascript 调试器断点不执行任何操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚 Chrome 调试工具.

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

我有 21.0.1180.60 m 的 chrome 版本.

I have chrome version 21.0.1180.60 m.

我采取的步骤:

  1. 我按下了 ctrl-shift-i 以调出控制台.
  2. 点击 Sources,然后选择我想要调试的相关 javascript 文件.
  3. 我通过在左侧行旁边的装订线中放置一个蓝色标签来设置我希望代码停止的断点.
  4. 我点击了我的网页(这是一个 php 呈现的页面)上启动 javascript 代码的按钮.
  5. 代码成功运行,没有停止.

我还注意到监视表达式也不起作用.它一直告诉我我想观察的变量未定义.

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.

进一步测试发现是我的代码导致断点失败.似乎它在 "$("#frmVerification").submit(function(){" 行上失败了.它没有进入那个 function() 内的断点.

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

以下是:

//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;
    });
});

推荐答案

我不知道为什么你的断点没有命中,但是进入你的代码的一种可靠方法是输入

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

debugger;

您希望代码在何处停止,然后在 chrome 开发人员工具窗口打开的情况下再次运行.

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

只需要注意一件小事,完成后一定要清理并删除调试器行.如果您曾经通过 YUI 压缩器运行 JavaScript 文件,debugger; 行的存在将导致它出错.

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.

这篇关于Chrome javascript 调试器断点不执行任何操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆