ajax请求真实服务器数据示例

// http://study.163.com/webDev/couresByCategory.htm
// http://study.163.com/webDev/couresByCategory.htm?pageNo=1&psize=20&type=20
// https://xhr.spec.whatwg.org/#states
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

var xhr = new XMLHttpRequest();
console.log('新建xhr对象,readyState的值:' + xhr.readyState);

xhr.open('GET', 'http://study.163.com/webDev/couresByCategory.htm?pageNo=1&psize=20&type=20');
console.log('使用open方法后,readyState的值:' + xhr.readyState);
xhr.send();

xhr.onreadystatechange = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
        console.log(xhr.statusText);
        console.log(xhr.responseText);
    }
};
原文地址:https://www.cnblogs.com/asheng2016/p/7435426.html