Home  >  Article  >  Web Front-end  >  Detailed explanation on the problem that JavaScript functions cannot be debugged in sub-pages

Detailed explanation on the problem that JavaScript functions cannot be debugged in sub-pages

巴扎黑
巴扎黑Original
2017-08-10 13:37:471110browse

[Introduction] I am working on a project recently, and I will encounter the situation where I cannot debug the javascript code when submitting it in a sub-page. Sometimes with this problem, we cannot see our sub-page normally in the browser. javascript code, so you can only use the original alert or console log

Recently I am working on a project, and I will encounter the situation where I cannot debug the javascript code when submitting it in a sub-page. Sometimes this happens The problem is that we cannot see the javascript code of our subpage in the browser normally, so we can only use the original alert or console.log(). Of course, this is also a solution, but sometimes, we just want to take a look. How the program runs, and you can also see what the value of each parameter is, so it is of great significance.

I will post a picture so that everyone can roughly understand when this problem will occur.

Detailed explanation on the problem that JavaScript functions cannot be debugged in sub-pages

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片

<script>  
function stopWatchDog(watchDogId) {  
    alert("aa");  
    var url = &#39;<s:url value="/watchDog/stopWatchDog"/>&#39;;  
    var params = {  
        watchDogId : watchDogId,  
    };  
    $.post(url, params, function(data) {  
        if (data.success) {  
            closeDialog();  
            tbGrid.send();  
        } else {  
            if (data.errorMsg != null && data.errorMsg != "") {  
                jAlert(data.errorMsg, "系统消息");  
            } else {  
                jAlert("停止异常", "系统消息");  
            }  
            $("#saveBtn").removeAttr("disabled");  
            $("#saveBtn").css("color", "white");  
        }  
    }, "json");  
}  
</script>

This is actually a function declaration. If you understand the javascript context, you will know that the function declaration is just a function loaded when the page context is loaded. name, its function content cannot be loaded normally.

If we switch to function self-execution or define this function declaration in function autonomy, then this problem can be solved.

avascript] view plaincopy在CODE上查看代码片派生到我的代码片

(function(){  
    function stopWatchDog(watchDogId) {  
        alert("aa");  
        var url = &#39;<s:url value="/watchDog/stopWatchDog"/>&#39;;  
        var params = {  
            watchDogId : watchDogId,  
        };  
        $.post(url, params, function(data) {  
            if (data.success) {  
                closeDialog();  
                tbGrid.send();  
            } else {  
                if (data.errorMsg != null && data.errorMsg != "") {  
                    jAlert(data.errorMsg, "系统消息");  
                } else {  
                    jAlert("停止异常", "系统消息");  
                }  
                $("#saveBtn").removeAttr("disabled");  
                $("#saveBtn").css("color", "white");  
            }  
        }, "json");  
    }  
})();

The above is the detailed content of Detailed explanation on the problem that JavaScript functions cannot be debugged in sub-pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn