1252748
1252748

Reputation: 15372

jquery ajax returned value does not respond as expected

When I call this ajax function, the object data prints out to the chrome console just fine:

$.ajax({
    type: "POST",
    cache: false,
    url: "login_user.php",
    data: "username=" + username + "&password=" + password + "&remember=" + remember,
    dataType: "json",
    success: function (data) {


        if (data == "FALSE") {

            $('#input_password').val("");

            alert("The username or password you have entered is incorrect.");

            return false;
        }

        console.log(data);

        console.log(data.accepted_terms);


        //always alerts 'not accepted'
        if (data.accepted_terms == "TRUE") {

            alert('accepted!');

        } else {

            alert('not accepted');
        }
    }

});

screenshot of chrome console

The undefined is the result of console.log(data.accepted_terms);

The php file being referenced returns this object with json_encode($login_info_array).

Am I incorrectly handling this returned object? Thanks for the help!

Upvotes: 1

Views: 95

Answers (1)

wirey00
wirey00

Reputation: 33661

Try this

console.log(data[0].accepted_terms);

Upvotes: 4

Related Questions