xhr发送请求-示例

关键代码：

Copy
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
console.log(response);
}
};

xhr.open('GET', 'http://192.168.0.109:5000/json', true);
xhr.send();

------
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
console.log(response[0].name);
}
};

xhr.open('GET', 'http://192.168.0.109:5000/json', true);
xhr.send();