为什么返回对象时未定义?

时间:2018-10-06 11:32:06

标签: javascript object return

function requests() {
    var request = new XMLHttpRequest();
    request.open('GET', '/orders_{{name}}_{{id}}');
    request.responseType = 'json';
    request.send();
    request.onload = function() {
        var orders = request.response['orders'];
        console.log(orders);
        return orders;
    }   
}

var response = requests();
console.log(response);

第一个console.log()打印出对象,但是第二个未定义。为什么会这样?

0 个答案:

没有答案