English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Généralement, lorsque nous utilisons des requêtes AJAX, elles sont asynchrones. Après l'exécution des résultats, les paramètres ne peuvent pas être obtenus en dehors de la méthode, mais ils peuvent retourner des données lors de l'exécution synchrone.
Le paramètre async de ajaxSettings est configuré, par défaut, il est true, ce qui signifie asynchrone. Lors de l'exécution synchrone, il est configuré avant la méthode : $.ajaxSettings.async = false; At this point, the method can return the corresponding data after execution.
Code block
/** * Get list */ function flowAtoms(){ //Request interface var listUrl = getServerUrl('XXXXXXX'); var param = {}; $.ajaxSettings.async = false; newlist=""; $.post(listUrl,param, function(data){ // Returned Json conversion var data_json = $.parseJSON(data); if(data_json.status==200){ // Initialize operation options var data=data_json.data; var funcHtml=""; $.each(data,function(i,v){ funcHtml+=v.name; ) newlist = funcHtml; } else { alert(data_json.message); } ) //Return the global variable newlist return newlist; }
This article using AJAX's post synchronous execution (implementation method) is all the content that the editor shares with everyone. I hope it can be a reference for everyone, and I also hope everyone will support the Yell Tutorial.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been edited by humans, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (when sending an email, please replace # with @ for reporting, and provide relevant evidence. Once verified, this site will immediately delete the infringing content that is suspected.)