I have a simple workaround which works for Angular.js within PhoneGap 3: If your development machine such as a laptop is online through a cable modem or wireless network, just do ipconfig, get the preferred IP, and then make your server run on that IP, with any port you wish.
Then the $resource call will work. ***** $resource just seems to hate 127. anything. **** (I previously tried serving on 127.0.0.2 (suspecting only 127.0.0.1 is the issue) but still not joy...) For example my laptop is connected on line through my AT&T private Hot Spot So I did. C:>ipconfig Windows IP Configuration Ethernet adapter Local Area Connection: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Wireless LAN adapter Wireless Network Connection: Connection-specific DNS Suffix . : lan Link-local IPv6 Address . . . . . : fe80::1d55:b740:cf2f:b19a%13 IPv4 Address. . . . . . . . . . . : 192.168.1.40 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1 So I started up my python web2py backend development server on my laptop (based on the Rocket python server) to server at http://192.168.1.40:8080 (It is actually web2py in the Google App Engine dev_appserver) Now this $resource call works for me from my Android app: var getResource = $resource('http://192.168.1.40:8080/rest/getPerson/:id', { id: '@id'}, { get: { method: 'GET' }, query: { method: 'GET', isArray: true} }); Result in Chrome Debugger: 1. XHR finished loading: "file:///android_asset/www/views/ViewPerson.html ". vendor.89a83346.js:4 <file:///android_asset/www/scripts/vendor.89a83346.js> 1. XHR finished loading: "http://192.168.1.40:8080/init/default/wiki/main Here is the XHR Detail: 1. Request URL: http://192.168.1.40:8080/init?id=1 2. Request Method: GET 3. Status Code: 303 OK 4. Request Headersview source 1. Accept: application/json, text/plain, */* 2. Cache-Control: no-cache 3. Pragma: no-cache 4. User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; Android SDK built for x86 Build/KK) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 5. Query String Parametersview sourceview URL encoded 1. id: 1 6. Response Headersview source 1. Cache-Control: no-cache 2. Content-Length: 67 3. Content-Type: text/html; charset=UTF-8 4. Date: Sun, 27 Jul 2014 16:25:08 GMT 5. Expires: Fri, 01 Jan 1990 00:00:00 GMT 6. Location: /init/default/wiki/main 7. Server: Development/1.0 NOTE: As you can see, there is no issue of any 'X-Requested-With' header. I did not need any code to deal with it because it is not there fortunately. Cheers! On Wednesday, August 29, 2012 9:01:28 PM UTC-5, Johno Scott wrote: > > My html5 mobile app is running locally on a file:// URL on Android (using > PhoneGap) so any call to a remote web service is going to be cross-domain. > > When I use $resource ( service in module ngResource ) to attempt a call to > a remote endpoint : > > .factory('Order', ['$resource', '$http', > function($resource, $http) { > return $resource('http://example.com/ api/orders/:_id', > {}, {}); > } > ]) > > I get an error like this : > > XMLHttpRequest cannot load http://example.com/ api/orders/ . Origin > file:// is not allowed by Access-Control-Allow-Origin. > > .. which I realise is your typical XHR cross-site security error. > > Is there an option to enable cross-domain support and relax this > restriction ? > > > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
