javascript - Joining ajax results? -


I will have to produce a result from 2 XMLHttpRequests how I can make requests concurrently and wait for both ends Can i do

I have something like this ...

  resp1 = ""; Req1.onreadystatechange = function (if {this.readyState = 4) resp1 == this.responseText;} req2.onreadystatechangefunction () {if (this.readyState = 4) Finish (this.responseText);} Function Finish (resp2 ) {If (resp1 == "") setTimeOut (end (resp2), 200); Other {... both are done ...}  

I have not tested it yet but I think it will work. Is there a better way? My code should be as quick and fast as possible.

You do not need a timer for this.

You only have to check in one callback whether the other has ended or not, and if so, then call ended .

For example:

  var resp1 = null, resp2 = null; Req1.onreadystatechange = function () {if (this.readyState === 4) {resp1 = this.responseText; If (resp2! == faucet) ends (); }}; Req2.onreadystatechange = function () {if (this.readyState === 4) {resp2 = this.responseText; If (resp1! == faucet) ends (); }};  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -