检查API响应并显示错误消息或成功消息

检查API响应并显示错误消息或成功消息

问题描述:

I have this code

<div class="error">Login failed </a>

url: 'myurl',
            type: 'POST',
            data: JSON.stringify(Login),
            contentType: "application/json",

Question: Check if API response is false display error message div if API response is true proceed it next.

$.ajax({
                type: "POST"
                , url: url
                , data: JSON.stringify(Login)
                , contentType: "application/json",
                , success: function (resdata) {
                    if (resdata == null || resdata == '') {
                        // handle this error case
                    } else if (resdata == 'true') {
                        // handle true case
                    } else if (resdata == 'false') {
                        // handle false case
                    } 
                }
                , error: function () {
                    // handle error case
                }
            });

You can handle by returning "true/false" from the API response.