PhoneGap and Windows Azure Mobile Services error: Login is only supported from http:// and https:// URLs. Please host your page in a web server

Just a quicky!

If you are building a PhoneGap app using the preview bits of Windows Azure Mobile Services and you get this error: “Login is only supported from http:// and https:// URLs. Please host your page in a web server” you need to include the cordova library.

Here was how we got this resolved:

The new MobileServices.Web-1.0.0.js client library does work with PhoneGap 2.3+ and IE8+. However, we haven’t yet published any documentation about how to work with PhoneGap, so we understand it will not be clear right now how to get started!

Currently, the downloadable quickstart project is intended only for browser apps, not for PhoneGap apps. However, it is possible to tweak it to make it work in PhoneGap as follows:

  1. Add the following to your page’s <head> tag: <meta name='viewport' content='width=device-width' />
  2. Change the <script> tag that references jQuery to specify an explicit protocol in the URL, i.e., change this line:

<script src='//'></script>

.. to this:

<script src=''></script>

  1. Add a script tag that references cordova-x.x.x.js (for example, <script src='cordova-2.5.0.js'></script> if you are using Cordova 2.5.0).
  2. If you are targeting Windows Phone 7.5., there is a known issue you’ll need to work around. Add the following line of code anywhere in your application before you instantiate a MobileServiceClient. For example, add this to the very beginning of app.js:

XMLHttpRequest.prototype.withCredentials = false;

We understand that this could be easier, so we are working on improving the quickstart. After an upcoming update, none of these steps will be necessary, except for adding a reference to cordova-x.x.x.js.



Comments (2)

  1. paul says:

    Hi Jeff,

    It may work with phonegap if hosted in a web context but it doesn't appear to work if hosted on a device (which I should imagine is the primary reason for using phonegap).

    It looks like the following line of code prevents any calls being made from code that is hosted on a devices filesystem:

    <pre>if(n+="?completion_type="+a+"&completion_origin="+encodeURIComponent(u),!(u&&(u.indexOf("http:")===0||u.indexOf("https:")===0))){c="Login is only supported from http:// or https:// URLs. Please host your page in a web server.",r(c,null);return}</pre>

    If I comment out this line it still doesn't work – I suspect because in a web context it opens another window which you may not be able to do in a native Web View?

    I'd be delighted if you were able to tell me that I was wrong or that I've just missed out something simple! Otherwise it would have saved me a lot of time and frustration of trying to get this working on mobile devices if it had been made clear in the quick starts. 🙂

  2. Jeff Sanders says:

    Hi Paul,

    This is a real old post so probably not applicable but was originally talking about phonegap on a device.

    Go ahead and post your question up on the Azure Mobile Services forum on MSDN:  Msdn forums – Azure Mobile Services:…/home


Skip to main content