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

时间:2016-02-10 15:13:51

标签: jquery json ajax

我正在使用jquery ajax提交表单。我想收到json的验证错误,Chrome调试器的控制台中有一条错误消息:

Uncaught TypeError: Cannot read property 'length' of undefined   

的javascript:

<script>
$.ajax({
            type: "POST",
            url: "{{ url('articles/') }}",
            dataType: 'json',
            processData: false,
            contentType: false,
            cache: false,
            data: formData
        })
        .done(function (data) {
            if (data) {
                $.each(data.responseJSON, function (key, value) {
                    var span = '#formAticle span[id=span-' + key + ']';
                    $(span + '>strong').text(value);
                    $(span).parent().parent().addClass('has-error');
                });
            }
            else {
                $(".alert-success").prop("hidden", false);
            }
        })
        .fail(function (data) {
            alert('The server failed somewhere');
        });
});

Chrome调试器中的响应json:

{
"title":["The title field is required."],
"content":["The content field is required."],
...
}

0 个答案:

没有答案