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

GetUserProfileByName error on site collection with port other than 80

Feb 25, 2016 at 8:17 AM
Edited Feb 25, 2016 at 8:18 AM
I'm using GetUserProfileByName to retrieve information from User Profile.
                    operation: "GetUserProfileByName",
                    async: false,
                    AccountName: <loginName>,
                    completefunc: function (xData, Status) {
                       // code process
On normal site with port 80, this works like a charm.
But when I create other web application on other port (like 9999), this function return following error.
XMLHttpRequest cannot load Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Port in URL of UserProfileService was duplicated (9999 becomes 99999999) so that it cannot return result. Is this a bug of SPServices?
Feb 25, 2016 at 2:46 PM
What version of SPServices are you using?

Feb 25, 2016 at 2:56 PM
sympmarc wrote:
What version of SPServices are you using?

I'm using version 2014.02
SharePoint Server 2013 SP1
Feb 25, 2016 at 3:53 PM
Edited Feb 25, 2016 at 4:11 PM
I think I found the problem, thanks for your full version of SPServices.
In the context initialization method SPServicesContext()
function SPServicesContext() {

        // The SharePoint variables ... and (if present) port.
        var siteRoot = location.protocol + "//" + + (location.port !== "" ? location.port : "");

        // SharePoint 2010 gives us a context variable
        if (typeof _spPageContextInfo !== "undefined") {
          // ....

    } // End of function SPServicesContext
Port is included in, so that concatenating with location.port causes the port duplicated.
Below are details of location, with win-ncav34droth is my server name:
host: "win-ncav34droth:81"
hostname: "win-ncav34droth"
href: "http://win-ncav34droth:81/sites/home/Lists/IsoDoc/DispForm.aspx?ID=1&Source=http%3A%2F%2Fwin%2Dncav34droth%3A81%2Fsites%2Fhome%2FLists%2FIsoDoc%2FV1%2Easpx&ContentTypeId="
origin: "http://win-ncav34droth:81"
pathname: "/sites/home/Lists/IsoDoc/DispForm.aspx"
port: "81"
protocol: "http:"
So changing to location.hostname and add ":" before port, is it enough? Or simply use directly.
I think this bug may cause problem for other operations, doesn't it?
Marked as answer by thanhma on 2/25/2016 at 8:29 AM
Feb 25, 2016 at 4:26 PM
Yes, this is a known bug. If I ever get the next release out, it's fixed there.

It seems to be pretty unusual for people to report this. I don't think that many people are using a port in their URLs.

You can just patch your version for now and you should be good to go.

Marked as answer by thanhma on 2/25/2016 at 8:29 AM