spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Detect all XMLHttpRequest calls are completed


If you can use jQuery you can use jQuery AJAX Deferred interface/methods and $.when method. $.ajax/$.post/$.get and other jQuery AJAX methods always return jQuery Deferred object:

$.when($.get('someUrl'),
$.get('anotherUrl')).then(function () {
    //all request complete
});

In native javascript you can use native Promise or any promise library:

Also good article about Promises - http://www.html5rocks.com/en/tutorials/es6/promises/.

Native Promise with XMLHttpRequest example:

function doAjaxRequest(method, url,
data){
  var promise = new Promise();
  var xhr = new XMLHttpRequest();
  xhr.open(method, url, true);

  // Register the event handler
  xhr.onload = function(){
    if(xhr.status === 200){
      promise.resolve("Done");
    } else{
      promise.reject("Failed");
    }
  }; 

  data = data || {};

  xhr.send(data);

  return promise;
}

Promise.all(doAjaxRequest('post', 'someUrl'),
doAjaxRequest('post', 'anotherUrl')).then(function
(values) {
    //all request complete
});

Categories : Javascript

Related to : Detect all XMLHttpRequest calls are completed
Meteor external API calls limit the calls or Sleep?
Good way to make pauses or intervals in Meteor is to use Timers, such as setTimeout() or setInterval()

Categories : Meteor
XMLHttpRequest: empty response
The true in zzz.open('GET', "http://freegeoip.net/json/", true); means that the request is asynchronous. That means you need to wait for the request to finish. var zzz = new XMLHttpRequest(); zzz.open('GET', "http://freegeoip.net/json/", true); zzz.onload = function(){ console.log(zzz.response); if (zzz.status === 200){ // Probably good to make the you got a success code. } };

Categories : Javascript
Cache pages using XMLHttpRequest
You are using one XHR object and keep writing over it in the loop. When you call open() it aborts the previous request. The for loop does not wait for the request. Either create a new XHR request or wait til the other request is done before you make the next request. var sites = ["/page1", "/page2", "/page3"]; var cache = {}; function xhrStart(url) { var xmlhttp = new XMLHttpRequest(); xm

Categories : Javascript
send a second request after the first is completed
Don't call the second request until the first completes: - (void) requestData: (int) forPlot { ... [urlRequest startWithCompletion:^(URLRequest *request, NSData *data, NSError *error, BOOL success) { if (success) { if (forPlot == 1) { ... dataForPlot = 2; [self requestData: dataForPlot]; } else if (forPlot == 2) {

Categories : IOS
Keep track of completed Futures
I would suggest using the standard Java AtomicInteger. You can increment it using the incrementAndGet() method, and obtain the current value via its get() method. import java.util.concurrent.atomic.AtomicInteger ... val completed = new AtomicInteger() val futures = for(i <- 0 until nSteps) yield future { ... val content = blocking { ... http request ... } process(content) compl

Categories : Scala
Recently Add
How to add items to sharepoint list from a html document?
Copying App Package Folder To Isolated Storage For Windows Store App
javascript save file from (sinatra's) streaming response
Use routeParams to create templateUrl in AngularJS
resize image using javascript
How to add and remove div's (input)
Onsen UI sliding menu
BxSlider is working but there is a blank space inside div
on button click delete from datatable and also from array
Jquery changing table th tag is not working properly
Get file height width before uploading using Javascript / Asp.net
Break out of Bootstrap modal dialog if unauthenticated
Listener for click on ANY element and read particular HTML-5 custom attribute when present?
What is the best way to use this in prototype method
Get Latitue and Longitude of the center in google map when draged
Jquery multidimensional Json parse
Not able to format date
How to force y position of one branch in d3 sankey plugin?
radio button doesn't come up from JS file
Calling PHP webservice method from Javascript/jQuery
Responsive menu - parent menu with link
'click' event firing multiple times, no solutions working
How to create Cordova Blackberry (Hybrid) application
Javascript date picker multiple select
How to do the marker management in google map
JQuery/Ajax Unexpected Identifier error
AngularJS Promise error catching
Populate form from child object
Jquery popup with scrollbar and column alignment
OpenLayers3 control panel
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.