Ajax dynamic for a tag href assignment does not perform a jump cause analysis and resolution _AJAX related

Source: Internet
Author: User
As one of the evaluation system to join a new function "questionnaire", I would like to use other people do a good survey questionnaire, with others have a good thing is: People do professional, interface beautification and so very user-friendly, but it requires you every time you set up a questionnaire after the release of the Web site, the client access every time is a change of address.

Each time the client clicks on the "questionnaire", it jumps to the appropriate page:

Click "Questionnaire" to enter the questionnaire page:

I use a tab, each time the administrator submits a "questionnaire"
Copy Code code as follows:

<li><a href= "" onclick= "Meizz (This)" > Questionnaire </a></li>

Click "Questionnaires" to call the Meizz function, which returns the "questionnaire" URL to be accessed via Ajax calls:
Copy Code code as follows:

<script type= "Text/javascript" language= "JavaScript" >
function Meizz (e) {
$.ajax ({
Async:false,//Set AJAX synchronization
Type: "Get",//get way
URL: ".. /handler/queryquestionnaire.ashx ",
Returns the data successfully, resolves the returned JSON data and displays it in the Course Information list
Success:function (Strjson) {
Check for data returned in the background
var DataArray = eval (Strjson);
E.href = dataarray[0]. questionnaire;//the URL to visit
},
Failed to return data, pop-up error display
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
alert (Xmlhttprequest.responsetext);
}
});
}
</script>

The phenomenon is e.href if placed on the function of the $.ajax can run, but put in the Ajax inside the binding dynamic return of the address, it can not run. After a depression, finally found the answer: because the AJAX default invocation is asynchronous, so the call processing callback function is not equal to the Ajax invocation of the value of href, the direct initiation of the HREF, where the href is a null value.

Workaround:Change the Ajax invocation method to synchronous, declaring that the Ajax invocation is synchronous:
Copy Code code as follows:

$.ajax ({
Async:false,//Set AJAX synchronization
}

This way, the execution of the href must wait for the AJAX call in the function to complete before triggering, and the desired result is obtained.
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.