This project has moved and is read-only. For the latest updates, please go here.

Methods of SPServices report as undefined

Feb 26, 2014 at 4:39 PM
I am successfully using SPServices all the time to look up other lists. But anytime I try to use SPServices functions, any function, the browser reports the function as undefined. I can't even get $().SPServices.Version() to work. Any ideas?
Feb 26, 2014 at 4:49 PM
Edited Feb 26, 2014 at 4:55 PM
If your calls to SPServices core are working, then it's loaded. Can you give an example of what you are trying to do where you see an error?

Feb 26, 2014 at 4:51 PM
Anything I do. I can't even get this to work:

Feb 26, 2014 at 4:55 PM
In the same page that you're using SPServices to do other things?

Feb 26, 2014 at 5:07 PM
Yes. I have a page that as a user selects a personnel name in a combobox it finds the name of the supervisor, phone, email, etc. Then I added a button that onclick all it does is alert($().SPServices.Version());

The combobox works continuously but the button click pops and error in the console that Version is undefined.
Feb 26, 2014 at 5:21 PM
That doesn't make a lot of sense. Try alerting $().SPServices.SPGetCurrentSite() instead.

What version of jQuery and SPServices are you using?

Feb 26, 2014 at 5:27 PM
jquery = 2.0.3
spservices = 2013.01
Feb 26, 2014 at 5:30 PM
I've done zero testing with jQuery 2.x, and I'd suggest that you stick to 1.10.x or 1.11.x. If you don't know why I'm making that suggestion, you should read up on what the differences are between the 1.x branch and the 2.x branch.

However, I doubt that would be the issue if other things are working. Did the $().SPServices.SPGetCurrentSite() alert work?

Feb 26, 2014 at 5:33 PM
No, I got "Cannot call method 'SPGetCurrentSite' of undefined".
Feb 26, 2014 at 5:49 PM
I really don't know what's going on. I think you'll need to step through the code to see what's going on.

Feb 26, 2014 at 6:00 PM
Let me suggest something better than "nothing works" - that is not goin to get you any help quick.

Can you post your code of the click event on the button together with the alert()?

My assumption is your loosing scope.

Paul T.

-- Sent from Mobile

Feb 26, 2014 at 6:47 PM
Paul's suggestion about the scope made something click. I checked my other code and it finally stood out the in my working code I had to put "window" in front of the call to SPServices.


This code is working now.
Feb 26, 2014 at 6:53 PM
Glad you figured it out... Good luck.

Paul T