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