Quantcast
Viewing all articles
Browse latest Browse all 6517

Closed Unassigned: SPServices failed to GetListItems when inside a webpart [10185]

Hi Marc -

I successfully ran SPServices (latest) from a blank web page in SP 2010 and was able to query a list on the same server. However, placing the same code in a web part failed. I traced through and found this was causing my problem:
```
// SharePoint 2010 gives us a context variable
if(typeof _spPageContextInfo !== "undefined") {
this.thisSite = _spPageContextInfo.webServerRelativeUrl;
this.thisList = _spPageContextInfo.pageListId;
this.thisUserId = _spPageContextInfo.userId;
// In SharePoint 2007, we know the site and UserId
} else {
this.thisSite = (typeof L_Menu_BaseUrl !== "undefined") ? L_Menu_BaseUrl : "";
this.thisList = "";
this.thisUserId = (typeof _spUserId !== "undefined") ? _spUserId : undefined;
}
```


Problem is when in a webpart, the site was coming back as "/" and the ajax script had the fqdn - so, the code thinks it's cross site scripting and things didn't go well. When the SPServices code is outside of the webpart, _spPageContextInfo was undefined and the code worked fine. In order to get it to work from within the webpart, i simply commened out the if and left the else condition code in place.

Can you shed some light on this? What should the _spPageContextInfo.webServerRelativeUrl return?

Thanks
Comments: No further information.

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>