We recently faced an issue after we configured our CRM 2011 site for SSL\HTTPS.
While using context.getServerUrl() method in our web resources we were getting the url value having http instead of https. And the other issue that we regularly faced was the Access Denied one if we access our CRM server either through localhost or through IP address.
These two wonderful posts talk about how to deal with these issues
getServerUrl() method returns the url according to the configured values in the Deployment Manager, not based on the url you have used to navigate to the page
var customServerURL = document.location.protocol + “//” + document.location.host +“/” + Xrm.Page.context.getOrgUniqueName();
Update : It works for on premise scenario only
Check this most helpful post on how to get the server url
Hope it helps