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ư:
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?
event.detail.request.xhr.response – montewhizdoh
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