SPServices v2013.02 Fails with error currentContext.thisSite is undefined

Dec 30, 2013 at 2:58 PM
Marc,

So I know I did some testing on this over the weekend, but in a O365 environment... This problem was not present there... At the office, however, running SP2010, I get an error from SPServices the first time I try to use the $().SPServices.SPGetCurrentSite()

The problem is the SPServicesContext() Constructor - It is using _spPageContextInfo.webAbsoluteUrl which in this production environment is not defined (maybe MS added that in a patch?). Here is what's defined for _spPageContextInfo:
{
    "webServerRelativeUrl":"/sites/PAUL/spdev",
    "webLanguage":1033,
    "currentLanguage":1033,
    "webUIVersion":4,
    "pageListId":"{5ae11fe5-89a4-498e-8dca-30030ef956bb}",
    "pageItemId":2,
    "userId":19,
    "alertsEnabled":true,
    "siteServerRelativeUrl":"/sites/PAUL",
    "allowSilverlightPrompt":"True"
}
I was using 2013.02 ALPHA3 before and did not get this error, so since I have my code under source control, I did a DIFF against the prior version... Looks like you changed SPServicesContext between ALPHA3 and BETA3 - it was using _spPageContextInfo.webServerRelativeUrl before.

Image

(I'm forking my version to fix it (setting it back to webServerRelativeURL)

/Paul.
Coordinator
Jan 2, 2014 at 6:13 PM
Edited Jan 2, 2014 at 6:13 PM
Paul:

I could have sworn I tested this fully on SP2010 and it worked. I've just pulled up my 2010 VM and here are the values I see:
Image

Is this consistent with what you've got?

M.
Jan 2, 2014 at 9:39 PM
Marc,
Yes, that matches the SP2010 environment I have access to.

Thanks.
Paul.
Coordinator
Jan 3, 2014 at 2:13 PM
I'm stuck in upgrading from Win7 to Win8.1 hell at the moment, but I plan to get a fix out ASAP. I'll need to change the ajaxUrl construction, too.

I can't believe I missed this.

M.
Jan 3, 2014 at 3:35 PM
Yeah, I saw your tweet that you were synchronizing the versions of windows at home :) - fun!

Hmmm. I made the change inreferenced above and have not hit any other issues. I'll take a quick look at the ajaxUrl.

Let me know if there is anything I can help with.



--

_________
Paul T

Coordinator
Jan 3, 2014 at 5:00 PM
Paul:

It's a matter of checking to see if the value for currentContext.thisSite ends in a slash or not correctly.

In the case of 2007 we can use the L_Menu_BaseUrl JavaScript variable where I've been making a call to WebUrlFromPageUrlResult. That value doesn't have a trailing slash.

Too many versions to test!

M.
Coordinator
Jan 3, 2014 at 5:01 PM
Jan 3, 2014 at 6:47 PM
Ahh. Got it. Thanks.




--

_________
Paul T