Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I get JSON data with jquery.ajax and dataType is "JSON" But I have some problem

This is my JSON data :

{
    "stock": {
        "head": [
            "name",
            "est",
            "date"
        ],
        "body": [
            {
                "row": [
                    "TEST",
                    "10.58",
                    "2013-09-05 13:37:20"
                ]
            }
        ]
    },
    "year": {
        "head": [
            "name",
            "est",
            "date"
        ],
        "body": [
            {
                "row": [
                    "TEST",
                    "0",
                    "2013-09-05 13:37:35"
                ]
            }
        ]
    }
}

This is my javascript code:

var getdata = $.ajax({
    type     :    'POST',
    url      :    'testjson.php',
    data     :    data,
    dataType :    'json'
});

getdata.done(function(result){

    var queryHead = result.stock.head; // This returns data
    var queryBody = result.stock.body; // But this doesn't return data. Empty

});

JSON data successfully returned, but not being parsed correctly. queryHead works fine but queryBody does not work

share|improve this question
4  
Seems like a problem with whatever is generating the JSON –  Explosion Pills Sep 16 '13 at 1:55
    
I try in jsfiddle.net and work in there. –  Soner Güler Sep 16 '13 at 1:58
1  
Are you sure you're getting the data you think you're getting? Firebug (for Firefox) has a handy Net tab that can monitor network traffic and confirm that the data is what it should be. –  Hobo Sapiens Sep 16 '13 at 2:00
    
@SonerGüler but you can't control what the server side sets with jsfiddle.net –  Explosion Pills Sep 16 '13 at 2:02
3  
You should be able to do some debugging on this yourself. Have you tried console.log(result) at least? –  meagar Sep 16 '13 at 2:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.