0

I'm currently developping a phonegap app with backbone but i'm not able to fetch my data from a cross domain website.

Testing the app on android gives me no results but testing it in chrome with "chromium-browser --disable-web-security" gives me a success response with the data I need.

Using phonegap I added the following lines of code:

config.xml

<access origin=".*"/>

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

json

[
 {
  "id":"918",
  "merk":"Yamaha",
  "type":"YZF R1"

... Its a valid json file.

My backbone collectionName.fetch() doesn't work, and doing a simple ajax call isn't working either inside the app. Is there any reason why I cannot fetch my data from the api in my phonegap android app!

I really could use some help
cheers!

Axel Ardu
  • 11
  • 1
  • 3

1 Answers1

0

From the file:// protocol there should be no limitations regarding same-origin, see here: http://en.wikipedia.org/wiki/Same_origin_policy#Corner_cases_and_exceptions

However it could be the server doesn't allow access to requests originating from file:// url's, check your server log. To doublecheck you could also access a publicly accessible webservice like Google Geocoding (see comment).

Edit: this is actually wrong... This likely is because cross domain is only allowed within the same protocol. Since your phonegap app runs from file:// this introduces problems when connecting via http(s):// protocol.

Jan Misker
  • 2,129
  • 16
  • 26
  • I thougd it was possible to do a cross-domain ajax call in phonegap because you can whitelist your website. Or did I assume wrong? – Axel Ardu Feb 03 '14 at 13:05
  • The phonegap whitelisting is only a way to limit/allow certain access, but the underlying same origin policy still applies. See here as well: http://stackoverflow.com/questions/6060786/file-url-cross-domain-issue-in-chrome-unexpected – Jan Misker Feb 03 '14 at 13:15
  • Did you try accessing a publicly accessible JSON service (so no limitation on the server side with respect to same origin), e.g. Google Geocoding webservice: https://developers.google.com/maps/documentation/geocoding/#JSON – Jan Misker Feb 03 '14 at 13:18
  • I did, and it is indeed possible to do that. My question now is, I am the onwer of the webserver and create the file myself. Is there any way of making it possible to get the data from the server in my mobile app? – Axel Ardu Feb 03 '14 at 13:46
  • In that case it becomes a question about your webserver, maybe best to consider this question answered and ask a new about how to configure your webserver. – Jan Misker Feb 03 '14 at 15:59