Introduction to code execution loading sequence on the jsp page

Source: Internet
Author: User

1. java is the code that runs on the server side. jsp is run on the server servlet, while javascript and html are the code that runs on the browser side. Therefore, the order of loading and execution is java> jsp> js.

2. Loading Sequence of js in jsp

JavaScript code on the page is part of the html code, so the page is loaded from top to bottom. Therefore, the js loading sequence is the order in which <script> labels appear on the page. <Script> the execution sequence of the label or external js files is the order in which the statements appear. The js execution process is also part of page loading.

2.1 global variables and functions defined in js scripts can be called in subsequent scripts. The call to the variable must have been previously declared; otherwise, the value returned by the variable is undefined. In the same script, the function definition can appear after the function call. If the function definition and call are in two script sections, the function call will report the function definition error before the function definition.

2.2 asynchronous ajax loading in js

The asynchronous loading of ajax may cause the statement to be executed in a different order. The following uses the problem I encountered during task execution as an example:

During initial page loading, you must send a request to jsp to obtain the data required for the page. In the ajax success function, data operations take a long time, the confirm and loadTree statements outside the ajax function are executed first than the statements after the data operation. The final value of using data in loadTree is null, and the global variable openTab_Id is null.

2.3 Control js execution sequence

You can use setTimeout (function (), time); To delay function loading.

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.