Home >Web Front-end >JS Tutorial >Solution to the problem that javascript functions cannot be debugged in subpages_javascript tips

Solution to the problem that javascript functions cannot be debugged in subpages_javascript tips

WBOY
WBOYOriginal
2016-05-16 17:03:16907browse

Recently when I was working on a project, I encountered a situation where I was unable to debug the javascript code when submitting it in a sub-page. Sometimes with this problem, we cannot see the javascript code of our sub-page in the browser normally, so we just You can use the original alert or console.log(). Of course, this is also a solution, but sometimes, we just want to see how the program runs, and at the same time, we can also see what the value of each parameter is, so The significance is quite large.

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

Copy code The code is as follows:

<script> <br>function stopWatchDog(watchDogId) { <br>alert("aa"); <br>var url = '<s:url value="/watchDog/stopWatchDog"/>'; <br>var params = { <br>watchDogId : watchDogId, <br>}; <br>$.post(url, params, function(data) { <br>if (data.success) { <br>closeDialog(); <br>tbGrid.send(); <br> } else { <br>if (data.errorMsg != null && data.errorMsg != "") { <br>jAlert(data.errorMsg, "System Message"); <br>} else { <br>jAlert( "Stop exception", "System message"); <br>} <br>$("#saveBtn").removeAttr("disabled"); <br>$("#saveBtn").css("color", "white"); <br>} <br>}, "json"); <br>} <br></script>

This is actually a function declaration. If you know javascript If you look at the context, you know that the function declaration is actually just the function name loaded when the page context is loaded, and 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.
Copy code The code is as follows:

(function(){
function stopWatchDog(watchDogId ) {
alert("aa");
var url = '';
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, "System Message");
} else {
jAlert ("Stop exception", "System message");
}
$("#saveBtn").removeAttr("disabled");
$("#saveBtn").css("color" , "white");
}
}, "json");
}
})();
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