Created
May 24, 2019 21:33
-
-
Save semyonf/ef7e4a1a2619add31bc26a6168b5dc5f to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/japalepimi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json'; | |
// 1. Создаём новый объект XMLHttpRequest | |
var xhr = new XMLHttpRequest(); | |
// 2. Конфигурируем его: GET-запрос на URL 'phones.json' | |
xhr.open('GET', endpoint, false); | |
// 3. Отсылаем запрос | |
xhr.send(); | |
// 4. Если код ответа сервера не 200, то это ошибка | |
if (xhr.status != 200) { | |
// обработать ошибку | |
console.error( xhr.status + ': ' + xhr.statusText ); // пример вывода: 404: Not Found | |
} else { | |
// вывести результат | |
console.log( xhr.responseText ); // responseText -- текст ответа. | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json'; | |
// 1. Создаём новый объект XMLHttpRequest | |
var xhr = new XMLHttpRequest(); | |
// 2. Конфигурируем его: GET-запрос на URL 'phones.json' | |
xhr.open('GET', endpoint, false); | |
// 3. Отсылаем запрос | |
xhr.send(); | |
// 4. Если код ответа сервера не 200, то это ошибка | |
if (xhr.status != 200) { | |
// обработать ошибку | |
console.error( xhr.status + ': ' + xhr.statusText ); // пример вывода: 404: Not Found | |
} else { | |
// вывести результат | |
console.log( xhr.responseText ); // responseText -- текст ответа. | |
} | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json'; | |
// 1. Создаём новый объект XMLHttpRequest | |
var xhr = new XMLHttpRequest(); | |
// 2. Конфигурируем его: GET-запрос на URL 'phones.json' | |
xhr.open('GET', endpoint, false); | |
// 3. Отсылаем запрос | |
xhr.send(); | |
// 4. Если код ответа сервера не 200, то это ошибка | |
if (xhr.status != 200) { | |
// обработать ошибку | |
console.error( xhr.status + ': ' + xhr.statusText ); // пример вывода: 404: Not Found | |
} else { | |
// вывести результат | |
console.log( xhr.responseText ); // responseText -- текст ответа. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment