XMLHttpRequest and Phonegap… Same Origin Policy or not?

♀尐吖头ヾ 提交于 2019-12-18 15:51:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17782052/xmlhttprequest-and-phonegap-same-origin-policy-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!