API- fetch :
fetch(url)
.then(function(data) {
})
.catch(function(error) {
});
, DOM. , .
, oldhchool XHR XMLHttpRequest:
var getJSON = function(url, successHandler, errorHandler) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.onreadystatechange = function() {
var status, data;
if (xhr.readyState == 4) {
status = xhr.status;
if (status == 200) {
data = JSON.parse(xhr.responseText);
successHandler && successHandler(data);
} else {
errorHandler && errorHandler(status);
}
}
};
xhr.send();
};
getJSON('data.json', function(data) {
}, function(status) {
});
API- Fetch API promise API-, , XMLHttpRequest callbacks.
So, both oldschool XMLHttpRequestXHR and the Fetch API do not block your DOM.
source
share