Unable to compare string value received via AJ

0

I'm having trouble comparing the string in the success function in an AJAX request.

AJAX Method:

$(function () {
$('.error').hide();
$(".form_submit").click(function () {
    $('.error').hide();
    var email = String($("input#email").val());

    //init ajax

    $.ajax({
    url: 'php/scripts/subscriber_exists.php',
    type: 'post',
    data: { email : email},
    error: function (xhr,error) {
        alert("xhr --> " + JSON.stringify(xhr) + " error --> " + JSON.stringify(error));
        console.log(xhr);
        console.log(error);
    },
    success: function (response) { 
        var success = $.trim(String(response));
        if (success == 'false' ) {
                 alert("Thank you so much!! --> [" + success + "]");
        } else
            alert("We understand your enthusiasm but you already are a subscriber! :D Thank you so much once again! [" + success + "]");
       }
});
    //end ajax
    return false;  
});});

I made sure that php sends string "true" or "false", here is the script.

subscriber_exists.php:

include_once '../class/mariaConnection.php';
include_once '../class/subscriber.php';

$email = $_POST['email'];
$maria = mariaConnection::getInstance();
echo json_encode(($maria->existsEmail($email)) ? 'true' : 'false');

Now, check the return value, return true and false.

The message must be different for the different outputs. Can you guys help me, please? Thanks in advance.

    
asked by anonymous 21.03.2018 / 13:19

0 answers