0

I have to make an ajax that counts the month of a submitted ticket, example, Jan:4 tickets, Feb:12 tickets, etc. Here is my code:

function createdAtChart(callback, createAt) {
    $.ajax({
        url: '/api',
        type: 'POST',
        data: {
            module: 'helpdesk/tickets',
            method: 'get',
            // params: [{'createdAt':createAt}]
            params: [
                {
                    'createdAt' : {
                        'before': createAt
                    }
                }
            ]
        },
        success: function (data, textStatus, jqXHR) {
            var data = JSON.parse(data);
            var total = data['hydra:totalItems'];
            console.log(total); //output 68
                var d = moment(data.createdAt).month();// The output is 8
                //8 means September
                createAt = d;
                        console.log('total = ', total); // output = 68
                if (callback) callback(d, total)
        }
    });
}

The problem is, I don't know how to get it from API. I access the ['hydra:member'], but only returns 18 data object, its because the paging. jsonld Please enlighten me. Any help would be appreciated.

EDITED Hydra view Here are the expanded hydra:view

danielpr
  • 97
  • 1
  • 14
  • Does the API provide a count per page variable? – Jon Mitten Sep 14 '17 at 04:43
  • @Smittles: yes sir. – danielpr Sep 14 '17 at 04:50
  • Is that your issue? That you're only able to get 18 results instead of the full set? If that's the case, set up the request to the API to get all results instead of just a fixed number of results. – Jon Mitten Sep 14 '17 at 04:52
  • @Smittles: yes. do you have a sample code? for counting all the items including paged API's. – danielpr Sep 14 '17 at 05:52
  • I misunderstand this post. What is your question exactly? – Jon Mitten Sep 14 '17 at 17:41
  • @Smittles: I finally found what I want. the createAt param should be like '2017-09-15'. But I have a new question now. – danielpr Sep 15 '17 at 07:15
  • But I have a new question now. I insert the param like this: `{'createdAt' : {'after': '2017-09-01'}},{'createdAt' : {'before': '2017-09-30'}}]}` which means to sort all created tickets after Sept 1st and before Sept 30th. I run the console.log and check the value from the API, but it returns different value. console returns all the data which is 68, but the API returned 17 (This is the correct value). I found [link]https://stackoverflow.com/questions/32515598/square-brackets-javascript-object-key but it returns error. – danielpr Sep 15 '17 at 07:26
  • You haven't asked any question yet. Please edit your post to ask a question. You'll get a lot more attention that way. – Jon Mitten Sep 15 '17 at 14:22

0 Answers0