0

Im creating a mobile app with Phonegap and Backbone.js. My app hits a url which returns an rss feed in xml format and this is to be loaded into the Backbone connection. However I am getting the error:

Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

In my res/xml/config.xml I have the line:

<access origin="*"/>

The phonegap docs at http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html, state that this should stop this type of error, but it's not.

I'm testing from localhost on a desktop browser. Could this be the issue?

user1716672
  • 1,073
  • 2
  • 20
  • 44

2 Answers2

1

Put his in your top in your PHP file that you make the request to:

header('Access-Control-Allow-Origin: *');

I take it that you use php :)

if now please say which language :)

Daniel
  • 2,002
  • 5
  • 20
  • 32
  • Unfortuneately I do not have access to the server.It is a Joomla website though. According to the answer here: http://stackoverflow.com/questions/13920782/phonegap-javascript-sending-cross-domain-ajax-request, I should not need to touch the server... – user1716672 Nov 05 '13 at 12:02
  • If you get this from your browser: XMLHttpRequest cannot load Origin null is not allowed by Access-Control-Allow-Origin... then 100% totally u need to put that code in. – Daniel Nov 05 '13 at 12:06
  • or...change your page and PHP script to support "JSONP" – Daniel Nov 05 '13 at 12:06
  • You are trying to access a resource that is not in the same domain as the page from which the script was downloaded, resulting in a "Cross Origin" security error. – Daniel Nov 05 '13 at 12:07
  • Phonegap got a whitelist aswell, but that dosent have anything to do with the server :) – Daniel Nov 05 '13 at 12:08
  • I do not have access to the server though. Im using it's rss feed to read latest news from the site. Maybe I need my own server and a proxy php script to go hit the external url, and then return the xml to my client? But I think its possible without this step – user1716672 Nov 05 '13 at 12:08
  • If you dont have access to the server you can make a middle point which will collect the data from the original server. Thats kinda a funky solution though. Try and get access to that server that would be the best ;) – Daniel Nov 05 '13 at 12:09
  • Ah, it works on my mobile device, but not on desktop – user1716672 Nov 05 '13 at 12:10
  • ok then so you havent tested it yet ;) I hope i was of some help.. please remember to close the question :-) – Daniel Nov 05 '13 at 12:12
0

I was testing in a browser, the whitelist in res/xml/config.xml only works on a mobile device.

user1716672
  • 1,073
  • 2
  • 20
  • 44