What's the difference between these two AJAX calls and which one would be more standard or effective?
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();