John Smith
John Smith

Reputation: 477

Phonegap / Converting website for mobile use

Currently I am building an app using phonegap for the Android and iOS systems. Essentially, it will be a website but I am running into some difficulties due the cross domain requests I need to make via ajax (same origin policy). Im wondering if its better to make the website on my own servers, where PHP is allowed, and then use a wrapper/frame in phonegap to emulate the site? How would that work?

Help appreciated

Upvotes: 0

Views: 1930

Answers (3)

GrayB
GrayB

Reputation: 539

You shouldn't be having this problem at all. PhoneGap apps are loaded on the device as local file:// pages, and the cross-domain security policy does not apply to them.

From the PhoneGap FAQ:

Q. I want to create an application for phonegap to access externally deployed web services via AJAX. How can i resolve the issue with the cross-domain security policy of XmlHttpRequest?

A. The cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply. (in Android,you may grant android.permission.INTERNET to your app by edit the AndroidManifest.xml)

Upvotes: 4

Tony Lukasavage
Tony Lukasavage

Reputation: 1937

If I understand correctly, you want to create a PHP proxy for a cross domain service so that you can access it with your mobile app using phonegap? This is a pretty common thing, its done a lot in Flash as well to get past cross domain restrictions.

For one of my demos I need to access Google Images from Flash. To do so I created a VERY simple PHP proxy on my server called imageproxy.php. Here's the complete code:

<?php
readfile($_POST['url']);
?>

Yep, thats its. So in your case, if you were using this PHP proxy on your server, you would send this proxy your target URL as a post variable and the proxy makes the request and returns the response via readfile().

Upvotes: 0

IgorGanapolsky
IgorGanapolsky

Reputation: 26831

If you are having issues with cross-domain requests then consider using something like jsonp as the data interchange format. Where are you requesting the data from?

Upvotes: 0

Related Questions