Code execution loading sequence in JSP pages introduction to _JSP programming

Source: Internet
Author: User
Tags function definition

1. Java is the code that runs on the server side, and the JSP runs in the server's servlet, while JavaScript and HTML are code that runs on the browser side. So the load execution order is JAVA>JSP>JS.

2. JS in the JSP in the loading sequence

The JS code on the page is part of the HTML code, so when the page loads it is loaded from the top down. So the order of JS loading is the order of <script> label appearing in the page. <script> tags inside or the introduction of the external JS file is the order of execution of its statements appear in the order in which the process of JS execution is also part of the page load.

2.1 Global variables and functions defined in the JS script can be invoked in a later script . The call to the variable must be previously declared, otherwise the value returned by the variable is undefined. In the same script, the function definition can appear after the function's call, and if the function's definition and invocation are in two script segments, the function call will report the function undefined error before the function definition.

Asynchronous loading of Ajax in 2.2 JS

Because of the asynchronous loading of Ajax, the execution order of the statements is not performed in the order in which they appear. Here's an example of the problem I encountered while doing my task:

When the page is initially loaded, you need to send a request to the JSP to get the data needed for the page, in the Ajax success function, the operation of the data takes too long, it will cause the confirm and loadtree outside the AJAX function to execute the statement after the data operation. The final use of data in the Loadtree is worth the time, when the global variable opentab_id is empty.

2.3 Control JS Execution order

You can use settimeout (function (), time) to delay the load of a function.

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.