Reputation: 305
I'm wrinting on a PhoneGap app that has the HTML and Javascript for the Navigation local and it should load the contend from the Web.
I don't have direct controll over the content Server so I can't change anything there.
The Content i want to get in to my app is based on a normal HTML website so i want to get for example the Text in da div or so.
What i have so far:
<script type="text/javascript">
var url = "http://example.org/"
updateGadget();
inervalID = setInterval("updateGadget();", 60 * 1000);
function updateGadget() {
$(document).ready(function () {
$.ajax(url, {}, function (response, status, xml) {
console.log(response);
});
});
}
</script>
The Problem is thad it doesn't work, it shows me nothing.
For developing is use a Webserver not directly PhoneGap. When i open the Website in Google Chrome it shows the error:
XMLHttpRequest cannot load http://example.org Origin http://example.org is not allowed by Access-Control-Allow-Origin.
in the Console.
I found the i should use this header:
header('Access-Control-Allow-Origin: *');
Where should i use it, if i put it in my HTML (PHP) file to the Top it does nothing an on the Server i want to Parse I cant put it.
Where is the Problem, and how can if fix thad? Or is there a better Way to do this? If possible i want to di it directly on the PhoneGap app without a secound server backend.
Upvotes: 3
Views: 1308
Reputation: 2057
This stackoverflow question has a solution for you.
Basic idea is to make $.get
request at http://whateverorigin.org/get?url=webpage-you-wish-to-scrap.com
Upvotes: 1