JavaScript functions cannot debug problem solving in subpages

Source: Internet
Author: User
Tags json

  When you encounter a situation where you can't debug JavaScript code when submitting to a subpage, here's a good workaround, and hopefully it will help.

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.     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, and if you know the JavaScript context, You know, actually. The function declaration is only the name of the function loaded when the page context is loaded, and its function contents are not loaded properly.     If we replace it with a function or define the function declaration in function autonomy, then we can solve the problem.     Code as follows: (function () {  function Stopwatchdog (watchdogid) {  alert ("AA");  var url = ' <s:url V Alue= "/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"); } }) (); 
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.