Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 12th, 2013  |  syntax: None  |  size: 1.43 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var URL = new Array();
  2.  URL[0] = "http://www.example1.com";
  3.  URL[1] = "http://www.example2.com";
  4.  URL[2] = "http://www.example3.com";
  5. var nRequest = new Array();
  6. for (var i=0; i<3; i++){
  7. nRequest[i] = new XMLHttpRequest();
  8. nRequest[i].open("GET", URL[i], true);
  9. nRequest[i].onreadystatechange = function (oEvent) {
  10. if (nRequest[i].readyState === 4) {
  11. if (nRequest[i].status === 200) {
  12.   console.log(nRequest[i].responseText);
  13.   alert(nRequest[i].responseText);
  14. } else {
  15.   console.log("Error", nRequest[i].statusText);
  16. }
  17.   }
  18. };
  19. nRequest[i].send(null);
  20. }
  21.        
  22. wRequest = new XMLHttpRequest();
  23. wRequest.open("GET", "http://www.example1.com", true);
  24. wRequest.onreadystatechange = function (oEvent) {
  25. if (wRequest.readyState === 4) {
  26. if (wRequest.status === 200) {
  27.   console.log(wRequest.responseText);
  28.   alert(wRequest.responseText);
  29. } else {
  30.   console.log("Error", wRequest.statusText);
  31. }
  32.   }
  33. };
  34. wRequest.send(null);
  35. }
  36.        
  37. for (var i=0; i<3; i++){
  38.    (function(i) {
  39.       nRequest[i] = new XMLHttpRequest();
  40.       nRequest[i].open("GET", URL[i], true);
  41.       nRequest[i].onreadystatechange = function (oEvent) {
  42.          if (nRequest[i].readyState === 4) {
  43.             if (nRequest[i].status === 200) {
  44.               console.log(nRequest[i].responseText);
  45.               alert(nRequest[i].responseText);
  46.             } else {
  47.               console.log("Error", nRequest[i].statusText);
  48.             }
  49.          }
  50.       };
  51.       nRequest[i].send(null);
  52.    })(i);
  53. }
clone this paste RAW Paste Data