Results 1 to 3 of 3

Thread: Get total number of objects returned from ajax request

  1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    1
      1  

    Default Answered: Get total number of objects returned from ajax request

    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
    Code:
        [{
            "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

    Code:
    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) { }
            });
    Last edited by eaglefox12; 23 Apr 2013 at 1:19 PM. Reason: correct json

  2. 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.

  3. #2
    Sencha User carol.ext's Avatar
    Join Date
    Jun 2007
    Location
    Littleton, Colorado, USA
    Posts
    708
    Answers
    25
    Vote Rating
    36
      1  

    Default

    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.

  4. #3
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    1
      0  

    Default Thank you

    Thank you sir... Length was the right answer I was looking for

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •