event $.post ajax alert status

Asked

Viewed 48 times

1

I’m using $.ajax post on jQuery so:

$('#btnSave').click(function () {
    let data = $('#addRunner :input').serializeArray();
    $.post('addRunner.php', data, function (json) {
        if (json.statusF == 'fail') {
            alert(json.message);
        }
        if (json.statusS == 'success') {
            alert(json.message);
            clearInput();
        }
    }, 'json');
});

statusF and the msg json for the alert, it is generated in php through these functions:

function fail($message) {
    die(json_encode(array('statusF' => 'fail', 'message' => $message)));
}


function success($message) {
    die(json_encode(array('statusS' => 'success', 'message' => $message)));
}

I display alerts in conditionals in PHP like this:

elseif(empty($fname) || empty($lname)) {
    fail('Please enter a first and last name.');
}
elseif(empty($gender)) {
    fail('Please select a gender.');
}
elseif(empty($minutes) || empty($seconds)) {
    fail('Please enter minutes and seconds.');
}

The point is that alerts are displayed until the variable is read $gender. The variables $minutes || $seconds no alert appears and the generated json comes with a f as shown below:

This is the json that correctly displays it is generated by the PHP function inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

After these alerts PHP generates json with a (F) in front and for alerts. This is the question: WHY DOES THAT F APPEAR IN THE GENERATED JSON AFTER THE ALERTS OF THE 3 <INPUT> INITIS? Look at the json generated after the conditionals as it has an (F) in front. Alerts stop being displayed. inserir a descrição da imagem aqui

I need help to display all alerts. However I don’t know why this f appears in json.

  • It seems to me that the "F" is a result of JSON that comes from PHP when there is a failure that meets the conditions that you use.

  • Somewhere else the code doesn’t have a echo, print or something so that might be printing that "f" on the screen

  • No. Conditions related to var $fname $lname and $gender run normally. and after that php starts generating json with this f

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.