2016-02-05 18 views
5

tôi sử dụng sắt-ajax:Polymer Sắt Ajax - Cách truy cập Phản hồi từ Yêu cầu sau Sự kiện Lỗi?

<iron-ajax 
    id="postLoginForm" 
    method="POST" 
    verbose 
    url="../../login" 
    content-type="application/json" 
    handle-as="json" 
    on-response="_handleLoginResponse" 
    on-error="_handleErrorResponse"></iron-ajax> 

Máy chủ luôn luôn đáp ứng với một lỗi nếu cơ thể yêu cầu rỗng:

Error: The request failed with status code: 422

này gây nên phương pháp của tôi _handleErrorResponse trong đó tôi muốn truy cập vào thực tế phản hồi, trông giống như sau:

{"email":["The email field is required."],"password":["The password field is required."]}

Đây là những gì _handleErrorResponse của tôi trông giống như:

_handleErrorResponse: function (event) { 
    console.log(event); 
    console.log(event.detail); 
    console.log(event.detail.error); 
    console.log(event.detail.error.message); 
    console.log(event.detail.request); 
    console.log(event.detail.response); 
    console.log(event.detail.request.response); 
}, 

Và đây là những gì đầu ra trông giống như:

Developer Tools Output

Vì vậy, làm thế nào để truy cập vào các phản ứng vì vậy mà tôi có thể xuất nó vào xem?

+1

event.detail.request.xhr.response – montewhizdoh

+1

Cảm ơn bạn ... Nếu bạn muốn xây dựng câu trả lời, thay vì nhận xét tôi có thể đánh dấu câu hỏi này là đã trả lời. – LoveAndHappiness

Trả lời

12

Tôi nghĩ rằng bạn có thể nhận được JSON lỗi ở đây:

event.detail.request.xhr.response 

Cheers!

+0

cổ vũ giao phối .... –

Các vấn đề liên quan