Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLHttpRequest and Phonegap... Same Origin Policy or not?

I'm still new to Phonegap and I am working with the Android SDK for some days now. At least I wanted to do a XMLHttpRequest to get data from my server. I knew about the Same Origin Policy before and I asked myself, how this should work with a "native app".

I searched the internet and found some topics, where people were telling others, that there is no Same Origin Policy on Phonegap, because it uses the file:// protocol and additionally there is a domain whitelist in it's config.xml.

On the other hand there were a bunch of topics of people having problems with XHR's and others told them, that this is because of the Same Origin Policy...

Well, I was confused, but I used my - on regular websites - working XMLHttpRequest snippet and put it into the Phonegap app. I tried the virtual device, but my request is not working.

Now I asked myself some questions:

  • Who is right? Is there Same Origin Policy on Phonegap or not?

If yes:

  • What function has that domain whitelist?

  • What's the best way to still get the data of my server?

like image 271
Fabi Avatar asked Jul 22 '13 07:07

Fabi


Video Answer


1 Answers

Yes, people are correct the Same Origin Policy is needed only in webApps not hybrid phonegap apps.

You need to check you domain whitelist, just check it in the config.xml in res --> xml folder.

For accessing xml web services you need to ensure your soap message is correctly formed. try to catch the exact error.

like image 178
Sheetal Avatar answered Nov 15 '22 06:11

Sheetal