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();
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct