dongnao6858
2012-07-23 18:54
浏览 39

jquery ajax返回值没有按预期响应

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!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulipi3742 2012-07-23 18:58
    已采纳

    Try this

    console.log(data[0].accepted_terms);
    
    打赏 评论

相关推荐 更多相似问题