PDA

View Full Version : Get total number of objects returned from ajax request



eaglefox12
23 Apr 2013, 1:17 PM
I get a json object by making this ajax request. I would like to know the total number of objects, but on alert, all I get is undefined. how do you get the number of object returned.
here is my json


[{
"Id": 1,
"Value": 10
},
{
"Id": 2,
"Value": 100
},
{
"Id": 3,
"Value": 1000
},
{
"Id": 4,
"Value": 10000
}]

and here is my ajax request. What I am looking for is total record = 4


Ext.Ajax.request({
url: 'MyApp/getRecord',
method: 'GET',
scope: this,
headers: { 'Content-Type': 'application/json' },
dataType: 'json',
success: function (response) {
this.returnedValue = Ext.JSON.decode(response.responseText);
alert(this.returnedValue.count);
},
failure: function (response) { }
});

carol.ext
23 Apr 2013, 1:46 PM
Try length instead of count. Or better yet play with it in the Firebug console, "alert" isn't very useful for figuring out what your object looks like.

eaglefox12
23 Apr 2013, 2:26 PM
Thank you sir... Length was the right answer I was looking for :)