I would like to create a web app with phonegap (I'm trying on Android emulator), but I have a problem with the "same domain policy": is there any way to disable this restriction. I need to load html/json data from an external server (not my own, so I can't modify it), but when I try to get data JQuery returns an undefined object. Here's my code:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Title</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='img/load.gif' alt='loading...' />";
var jsonUrl = "external url";
$("#result").html(ajax_load);
$.getJSON(jsonUrl, function(json) {
var result = json.responseData;
$("#data").html("Result: " + result);
});
</script>
</head>
<body>
<div id="data"></div>
</body>
</html>
PhoneGapTestActivity
public class PhoneGapTestActivity extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Searching online and reading other questions, I tried to set the whitelist in the file phonegap.xml
<?xml version="1.0" encoding="UTF-8"?>
<phonegap>
<access origin="*" subdomains="true" />
</phonegap>
But what I got is: "Result: undefined". Thanks a lot!
EDIT: After many tries, I noticed that the request works (I received the data), but there was some issues while accessing json data contents, but now it works!. Thanks for all answers.