GetUserProfileByName error on site collection with port other than 80

Feb 25 at 7:17 AM
Edited Feb 25 at 7:18 AM
I'm using GetUserProfileByName to retrieve information from User Profile.
 $().SPServices({
                    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 http://xxxx.cloudapp.net:99999999/sites/xxx/_vti_bin/UserProfileService.asmx. 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?
Coordinator
Feb 25 at 1:46 PM
What version of SPServices are you using?

M.
Feb 25 at 1:56 PM
sympmarc wrote:
What version of SPServices are you using?

M.
I'm using version 2014.02
SharePoint Server 2013 SP1
Feb 25 at 2:53 PM
Edited Feb 25 at 3: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.host + (location.port !== "" ? location.port : "");

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

    } // End of function SPServicesContext
Port is included in location.host, 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 location.host to location.hostname and add ":" before port, is it enough? Or simply use location.host 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
Coordinator
Feb 25 at 3:26 PM
Yes, this is a known bug. If I ever get the next release out, it's fixed there.
https://raw.githubusercontent.com/sympmarc/SPServices/master/src/core/SPServices.utils.js

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.

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