Ajax Help

Techsavy used Ask the Experts™

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.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
can you tell us the value of 'data' by alerting the same?
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".

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial