M
M
Mariik2014-11-18 15:12:40
JavaScript
Mariik, 2014-11-18 15:12:40

How is external data exchange done in Cordova/Phonegap?

I decided to try developing mobile applications for myself
using the Cordova framework. Yes, I know it's not the best way. Naive code is much better. To study the framework, I decided to make a simple client for a news site. Fortunately, the site has an RSS feed. The first thought was to use an Ajax request. But cross-domain requests are blocked by the browser, and the use of JSONP is not suitable in every case. So what's the best way to do it? Enter an intermediate server that receives XML as input and returns JSONP? Resource intensive.
Maybe there is another way out? How is the exchange of external data organized in Cordova?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-11-18
Protko @Fesor

Yes, I know it's not the best way.

For business applications, it's quite normal. And for prototyping. Separately, I recommend looking at Ionic.
Yes, in the browser (and for the same chrome, this can be disabled by running it with --disable-web-security). And you have a webview. Checking for cross-domain requests is implemented at a higher level and does not directly affect the work when using webview. There are also options for cordova itself. There is also CORS, since everything else is a hack. And yes, use REST for interaction.

_
_ _, 2014-11-18
@AMar4enko

It's not entirely obvious, but when the index.html of an html5 app is opened in Cordova, it's opened using the file:// protocol - in this case, cross-domain request policies don't apply.
Therefore, what does not work due to CORS in your browser during debugging will work fine on the device.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question