开发者

Failure to parse json correctly...not sure what the issue is here?

开发者 https://www.devze.com 2023-02-19 04:13 出处:网络
I have almost no experience with json and I\'m not sure how I\'m devia开发者_开发问答ting from the textbook here.I have a very simple json object that I want to parse.It is not registering a value for

I have almost no experience with json and I'm not sure how I'm devia开发者_开发问答ting from the textbook here. I have a very simple json object that I want to parse. It is not registering a value for data.user_status. Where I am going wrong here?

$('input#login_submit').click(function(event){
    $.post("/login_ajax/", {post:1,username:$('input#ajax_username').val(), password:$('input[name=password]').val()}, //could also use $(this).serialize() here to capture all form inputs
        function(data){
            if(data.user_status==1){
                 ......(functions happen)

    },'json');
    return false;
    });

Firebug shows that I have returned an

Object { user_status=1, user_favorite=1, flag_record=1}

How do I handle this?

Thanks


I had to iterate over the json object


I dont see where you are telling the $.post that you expect a json object back from the post:

(<?php echo json_encode(array("name"=>"John","time"=>"2pm")); ?>).
$.post("test.php", { "func": "getNameAndTime" },
  function(data){
    alert(data.name); // John
    alert(data.time); //  2pm
}, "json");

The above example is ripped from the jquery docs, but you can see they pass the 'json' datatype as a part of the $.post, and if passed the result will be parsed into a json object on your behalf.

0

精彩评论

暂无评论...
验证码 换一张
取 消