I want to wait for the XHR to open after I continue with the program but synchronous XHR is deprecated in chrome api. How can I get around this?
            Asked
            
        
        
            Active
            
        
            Viewed 208 times
        
    0
            
            
        - 
                    possibly a duplicate of [How to return the response from an Ajax call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) -- if you have concerns not addressed by that Q&A, please [edit] your question to clarify what you don't understand. – apsillers Feb 16 '15 at 16:33
1 Answers
0
            
            
        Using a callback to continue execution seems like the best method. Without a clear example of your project here's a generalized option:
function performRequest() {
   // ... Some code
   var xhr = new XMLHttpRequest();
   xhr.open("GET", "/bar/foo.txt", true);
   xhr.onload = function (e) {
      if (xhr.readyState === 4) {
        useRequest(xhr.responseText);
      }
   };
}
function useRequest(data) {
  // Continue with your application
}
performRequest(); 
    
    
        jpschroeder
        
- 6,636
- 2
- 34
- 34
