Ajax Help

Hi,

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;

            $.ajax({

                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.
TechsavyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurvinder Pal SinghCommented:
can you tell us the value of 'data' by alerting the same?
0
BardobraveCommented:
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".
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.