Sign in
Log inSign up

What's the difference between these two AJAX calls and which one would be more standard or effective?

Steven Ventimiglia's photo
Steven Ventimiglia
·Aug 22, 2017

Example #1:

var xhr = new XMLHttpRequest(); 
xhr.onreadystatechange = function() {   
4 === xhr.readyState && (data = JSON.parse(xhr.responseText)); 
}, xhr.open('GET', ''), xhr.send();

Example #2:

var xhr = new XMLHttpRequest(); 
xhr.onreadystatechange = function() {     
  if (xhr.readyState === 4) { 
    data = JSON.parse(xhr.responseText);     
  } 
}; 
xhr.open('GET', ''); 
xhr.send();