JavaScript in subpages function cannot debug problem resolution _javascript Tips

Source: Internet
Author: User
In a recent project, you will not be able to debug JavaScript code when submitting to a child page, sometimes this problem, we can not normal in the browser, see our child page JavaScript code, so can only use the original alert or Console.log (), of course, this is a solution, but sometimes, we want to see how the program is actually running, but also can see what each parameter is exactly what value, so the meaning is relatively large.

I put a picture on it and you'll probably know when it's going to happen.
Copy Code code as follows:

<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 Exception", "System Message");
}
$ ("#saveBtn"). Removeattr ("Disabled");
$ ("#saveBtn"). CSS ("Color", "white");
}
}, "JSON");
}
</script>

This is actually a function declaration, if you understand the JavaScript context, you know that the function declaration is only loaded when the page context load the function name, its function content can not load normally.

This problem can be solved if we change the function itself or define the function declaration in function autonomy.
Copy Code code as follows:
(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 messages");
} else {
Jalert ("Stop Exception", "System Message");
}
$ ("#saveBtn"). Removeattr ("Disabled");
$ ("#saveBtn"). CSS ("Color", "white");
}
}, "json");
}
}) ();
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.