minor renovations, beautify round 2 (final)

This commit is contained in:
Ilya Kantor 2015-03-12 10:26:02 +03:00
parent fad6615c42
commit 8410ce6421
212 changed files with 1981 additions and 1717 deletions

View file

@ -3,31 +3,31 @@
```js
function loadPhones() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'phones.json', true);
var xhr = new XMLHttpRequest();
xhr.open('GET', 'phones.json', true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
button.parentNode.removeChild(button);
if (xhr.status != 200) {
// обработать ошибку
alert(xhr.status + ': ' + xhr.statusText);
alert( xhr.status + ': ' + xhr.statusText );
} else {
*!*
try {
var phones = JSON.parse(xhr.responseText);
} catch(e) {
alert("Некорректный ответ " + e.message);
} catch (e) {
alert( "Некорректный ответ " + e.message );
}
showPhones(phones);
*/!*
}
}
button.innerHTML = 'Загружаю...';
@ -37,12 +37,12 @@ function loadPhones() {
*!*
function showPhones(phones) {
phones.forEach(function(phone) {
var li = list.appendChild(document.createElement('li'));
li.innerHTML = phone.name;
});
phones.forEach(function(phone) {
var li = list.appendChild(document.createElement('li'));
li.innerHTML = phone.name;
});
}
}
*/!*
```

View file

@ -18,27 +18,27 @@
*!*
// 1. Создаём новый объект XMLHttpRequest
*/!*
var xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest();
*!*
// 2. Конфигурируем его: GET-запрос на URL 'phones.json'
xhr.open('GET', 'phones.json', false);
xhr.open('GET', 'phones.json', false);
*/!*
*!*
// 3. Отсылаем запрос
*/!*
xhr.send();
xhr.send();
*!*
// 4. Если код ответа сервера не 200, то это ошибка
*/!*
if (xhr.status != 200) {
// обработать ошибку
alert(xhr.status + ': ' + xhr.statusText); // пример вывода: 404: Not Found
alert( xhr.status + ': ' + xhr.statusText ); // пример вывода: 404: Not Found
} else {
// вывести результат
alert(xhr.responseText); // responseText -- текст ответа.
alert( xhr.responseText ); // responseText -- текст ответа.
}
```
@ -284,7 +284,7 @@ xhr.timeout = 30000; // 30 секунд (в миллисекундах)
```js
xhr.ontimeout = function() {
alert('Извините, запрос превысил максимальное время');
alert( 'Извините, запрос превысил максимальное время' );
}
```
@ -370,7 +370,7 @@ xhr.onreadystatechange = function() {
if (this.status != 200) {
// обработать ошибку
alert('ошибка: ' + (this.status ? this.statusText || 'запрос не удался') );
alert( 'ошибка: ' + (this.status ? this.statusText || 'запрос не удался') );
return;
}