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

Spservices getlist items not working when called over web to html page

Mar 21, 2014 at 1:09 AM
Edited Mar 21, 2014 at 1:54 AM

I have 2 pages that are using the same GetListItems and SPGetListItemsJson calls in a referenced .js. file.
One is a standard .aspx that has a master page and another is a standalone html page.

Both pages work as expected when accessed locally through the intranet but the html page fails to get any list data when accessed externally over the internet, while the aspx page works fine.

I think its somehow a a relative vs absolute issue for the following reasons:
  1. When I insert an alert to show SPGetCurrentSite(), the html file returns the full site address "http://portal/sites/mysite" whereas the aspx returns a relative address - "/sites/mysite"
  2. If I use an aspx page without a master page reference I have the same problem as the html - it works fine on the intranet and will make calls like SPGetCurrentSite, SPGetUser etc, but fails on all list calls.
  3. I have tried both setting the url and not in the GetListItems call and it makes no difference to the result
Anyone come across this issue or have any ideas how to solve it?
Mar 21, 2014 at 1:57 AM
Are you getting any errors in the console? Also, do you actually see the WebServices calls being made to the server?

Paul T.

-- Sent from Mobile

Mar 22, 2014 at 7:05 AM
Hi, thanks for the quick reply.

Took me a while to get back to this because I had to access from a different location.

Looks like a https vs http issue. I am getting this error in console on a few of the calls. Seems to only happen in html but not aspx with master. Any thoughts? could modify underlying SpServices js I suppose.

The page at 'https://xxx.html' was loaded over HTTPS, but displayed insecure content from 'http://xxx/_vti_bin/Lists.asmx': this content should also be loaded over HTTPS.

Mar 22, 2014 at 3:30 PM
Ok. So this is progress. Can you post your code that is calling SPServices and causing these errors? That is needed to narrow down the method.

SPServices should be honoring the current page protocol and not change it on you.

Paul T.

-- Sent from Mobile

Mar 22, 2014 at 5:42 PM
Edited Mar 22, 2014 at 5:44 PM
I just checked and nowhere that I can see in SPServices am I specifying the protocol. I do use http in the namespaces, but that's cool.

My guess is that the webURL is specified with the protocol? You can fix this by doing this:
webURL: location.protocol + "//domain/site/"
Mar 22, 2014 at 6:21 PM
That's what I was thinking too Marc. Looking at his code will hopefully clarify that.
What was not sure about: when SPGetCurrentSite() can determine the current web URL based on js variables (which is this case sounds to be the case - strait HTML file), SPServices uses the root site webservice to get the webURL using the curent page full address. In that case I'm assuming you honor the current page's protocol.

Paul T.

-- Sent from Mobile

Mar 22, 2014 at 6:33 PM
            url: "/_vti_bin/Webs.asmx",
Mar 22, 2014 at 11:00 PM
Success! Thanks for your time Paul and Marc,

webURL: location.protocol + "domain/site/" was the key. I had tried this previously, however in my case because of the structure of this site I needed to use location.protocol + "domain/subdomain/sites/site" which I didn't think about till this discussion.

Just for information sake, the html page is needed because we are using this in an IOS web app and the sharepoint .aspx pages do not play as nicely there. Great to have the new JSON functions for this particular use Marc - thanks a lot.