The data obtained by the AJAX request cannot be assigned to a global variable problem summary

Source: Internet
Author: User

First, Summary:

1. Description of the problem:

Today the project encountered in the process of displaying detailed information in the form of Ajax request data can not be assigned to the global variables, from the list page into the details page, after the detail page is rendered, the JS file will be called the interface to the server to request data, In addition to sending AJAX requests to the server after the details page is loaded, there are several form control properties on the details page that require the server to fetch the data that is required to be displayed in the actual project.

The following code, which changes the value of a form control directly in an AJAX request, avoids assigning a value to a global variable.

A workaround to assign a value to the global variable, set Async to False for the AJAX request, indicating that the request is a synchronous request:

The asynchronous request does not block code execution, the program executes from the top down, and the synchronization request must wait until the previous code finishes executing. Therefore, the data of the AJAX request cannot be assigned to a global variable (the global variable does not have a value after the assignment) because the AJAX request has not been executed until the subsequent code executes. The AJAX request is set to a synchronous request to ensure that the AJAX request is executed before assigning a value to the global variable.

The data obtained by the AJAX request cannot be assigned to a global variable problem summary

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.