Why ajax is showing me 0 on the screen when backend flask return str(0) and str(2) value of a function?

Solution 1
function ValidatePassword() {
    var mobileno = $('#lmobileno').val();
    var password = $('#password').val();
    if (validate_mobile(mobileno)==true && password != null) {
        $('#overlay').fadeIn();
        $.ajax({
            type: "POST",
            url: "/signin",
            contentType: 'application/json',
            data: JSON.stringify({
                "lmobileno": mobileno,
                "password": password
            }),
            dataType: 'json'
        }).done(function (data) {
            $('#overlay').fadeOut();
            if (data == 1) {
                $('#otp').show();
                $('#lmobileno').hide();
                $('#password').hide();
            }
            else if(data==2) {
                $('#overlay').fadeOut();
                Swal.fire({
                    icon: 'error',
                    title: 'Invalid password or phone number',
                    text: 'Sign in again',
                    width: 500,
                    showConfirmButton: false,
                    showCloseButton: true
                })
            }
        });
    }
};


Solution 2
from flask import jsonify # import this in top
return jsonify({"msg": "0"}) # do same for 1 and 2 as well
if(data.msg == 0)