My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

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();