Javascript functions cannot debug the problem resolution in child pages

  • 2020-03-30 01:24:13
  • OfStack

In a recent work on a project, will encounter when submitted in child pages will not able to debug javascript code, sometimes this kind of problem, we can't normal in the browser, see our child pages javascript code, so can only be used original alert or console. The log (), of course, this also is a kind of solution, but sometimes, how is it that we want to have a look at the program running, at the same time also can see what each parameter value, so the meaning of the spring.

I'll post a picture so you can get a sense of when this problem might occur.
 
<script> 
function stopWatchDog(watchDogId) { 
alert("aa"); 
var url = '<s:url value="/watchDog/stopWatchDog"/>'; 
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 abnormal ", " System message "); 
} 
$("#saveBtn").removeAttr("disabled"); 
$("#saveBtn").css("color", "white"); 
} 
}, "json"); 
} 
</script> 

This is actually a function declaration, and if you know the javascript context, you know that the function declaration is just the name of the function that was loaded when the page context was loaded, and the contents of the function were not loaded properly.

We can solve this problem if we change to function self-execution or if we define the function declaration in function autonomy.
 
(function(){ 
function stopWatchDog(watchDogId) { 
alert("aa"); 
var url = '<s:url value="/watchDog/stopWatchDog"/>'; 
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 abnormal ", " System message "); 
} 
$("#saveBtn").removeAttr("disabled"); 
$("#saveBtn").css("color", "white"); 
} 
}, "json"); 
} 
})(); 

Related articles: