Because the No. 1 evaluation system needs to add a new function "questionnaire", I want to keep the questionnaire prepared by others. The advantage of using others is that they are specialized in other people's work, ui beautification is very user-friendly, but it requires you to publish the website after you set up the questionnaire every time, and the client accesses the changed address every time.
Each time the client clicks "questionnaire", it will jump to the corresponding page:
Click "questionnaire" to go to the questionnaire page:
I use the label to access the "questionnaire" submitted by the Administrator each time"Copy codeThe Code is as follows: <li> <a href = "" onclick = "meizz (this)"> questionnaire </a> </li>
Click "questionnaire" and call the meizz function. The function returns the "questionnaire" URL to be accessed through ajax:Copy codeThe Code is as follows: <script type = "text/javascript" language = "javascript">
Function meizz (e ){
$. Ajax ({
// Async: false, // set ajax Synchronization
Type: "get", // get Method
Url: "../handler/QueryQuestionnaire. ashx ",
// The returned data is successfully parsed and displayed in the course information list.
Success: function (strJson ){
// Check the data returned by the background
Var dataArray = eval (strJson );
E. href = dataArray [0]. Questionnaire; // URL to be accessed
},
// Failed to return data. An error is displayed.
Error: function (XmlHttpRequest, textStatus, errorThrown ){
Alert (XmlHttpRequest. responseText );
}
});
}
</Script>
E. href can be run on $. ajax of the function, but cannot be run if it is bound to the dynamic return address in ajax. After being depressed, I finally found the answer: Because ajax calls are asynchronous by default, instead of assigning values to href for ajax calls to handle callback functions, I directly initiate href, here, href is null.
Solution:Change the ajax call method to synchronous, and declare that the ajax call method is synchronous:Copy codeThe Code is as follows: $. ajax ({
Async: false, // set ajax Synchronization
}
In this way, the href execution will be triggered only after the ajax call in the function is completed, and the desired result is obtained.