Ajax Help


I am using following JQuery function to make an async call to SharePoint list data and return the count. However, when i run this function, I get data.d.results.length is not defined.

 function GetActionLogItems(result) {
            var violationCount = 0;


                url: "/_vti_bin/listdata.svc/ActionLog?$filter=((PropertyIDId%20eq%20" + result.Id + ")%20and%20(ActionTypeId%20eq%203))",
                asynch: false,
                success: function (data) {

                    violationCount = data.d.results.length;



            return violationCount;


Please help, What i want from this function is the number of items returned from my Ajax call.
Who is Participating?
First of all, there is a typo on your code:

The attribute for making calls sincronous on $.ajax is async, not asynch.

If you have this on your code you'll surely receiving an error on your javascript and your function won't execute.

If on your code it's ok then the problem surely comes from the url call. Try to check if the call is reached, if you cannot check it you can, as gurvinder suggest, alert (data) to see if the call returns anything.

If the url is ok and the call is reached maybe the error is in result.Id, it may be containing a value different from what you expect, or even a null, and the url you call returns an unexpected "data".
Gurvinder Pal SinghCommented:
can you tell us the value of 'data' by alerting the same?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.