jQuery.Deferred异常:无法读取未定义的属性'length'TypeError:无法读取未定义的属性'length'

时间:2018-03-27 11:33:44

标签: php jquery

$.post("#", params).then(function (response) {
    if (obj['error'] != 1) {
        var html = '';
        for (var i = 0; i < response['data'].length; i++) {
            console.log('data' + i, response['data'][i]);
            html += '<tr>';
            html += '<td>' + response['data'][i]['wallet_type'] + '</td>';
            html += '<td>' + response['data'][i]['balance'] + '</td>';
            html += '<td>' + response['data'][i]['wallet_address'] + '</td>';
            html += '</tr>';
        }
    }
});

我找到了

  

未捕获的TypeError:无法读取未定义的属性“长度”

在控制台中

我无法显示我的结果。

1 个答案:

答案 0 :(得分:0)

首先,您需要在控制台中检查响应中的响应数组。我认为您的响应数组未设置。 恩。 console.log(response);

<script>
    var response={"data":[{"id":556,"user_id":333,"email":"alokkr@dispostable.com","name":"alokkr@dispostable.com","wallet_id":"5ab7dfaa39062807cc3d0659a5ee9634","wallet_address":"QNqpGLNDhsCLWsqbz4joJHnh7QBQYhWQhz","wallet_type":"ltc","balance":0,"is_custom":false,"is_test":"0","created":"2018-03-25T17:44:50","updated":null},],"error":0,"msg":[]}
    //console.log(response['data'].length);        
    var html='';
    for (var i = 0; i < response['data'].length; i++) {
    console.log('data' + i, response['data'][i]);
    html += "<table border='1'>";
    html += "<tr>";

    html += '<td>' + response['data'][i]['wallet_type'] + '</td>';
    html += '<td>' + response['data'][i]['balance'] + '</td>';
    html += '<td>' + response['data'][i]['wallet_address'] + '</td>';
    html += '</tr>';
    html += '</table>';
    }
    document.write(html);
 </script>