English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Synchronous Execution Using Ajax Post (Implementation Method)

Generally, when we use AJAX requests, they are asynchronous. After the operation is executed, the parameters cannot be obtained outside the method, but data can be returned when the synchronous execution is used.

The 'ajaxSettings.async' parameter is set, by default it is true, indicating asynchronous, and synchronous is set before the method: 
$.ajaxSettings.async = false; At this point, after the method is executed, the corresponding data can be returned.

Code block

/** * Get the list */
function flowAtoms(){  
//Request interface 
  var listUrl = getServerUrl('XXXXXXX'); 
  var param = {};
  $.ajaxSettings.async = false;  
   newlist="";  
  $.post(listUrl,param, function(data){   
    // Return the 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 on the synchronous execution of AJAX POST (implementation method) shared by the editor is all the content shared with everyone. I hope it can be a reference for everyone, and I also hope everyone will support and cheer for the tutorial.

Statement: The content of this article is from the Internet, 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 manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)

You May Also Like