Reputation: 3965
I am trying to generate a list of downloadable text files from a website using phonegap and jquery. This list should be grabbed automatically when the application is loaded. So if another text file is added to the website and then the app is reopened, the newly added text file should also be in the list.. I am very new to these technologies so I would appreciate it if someone could tell me what I'm doing wrong here. This is what my index.html looks like:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
</head>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
$.ajax({
url: "http://www.samplesite.com/files/", //I feel like this is wrong
context: document.body,
success: function(){
document.write(document.body); //I feel like I'm doing something very wrong here too
}
});
}
</script>
</html>
Upvotes: 0
Views: 113
Reputation: 2807
By requesting http://www.samplesite.com/files/
, you'll get the raw html code of the page.
Then you need to parse it manually (in the success function) to retrieve the url. If you are lucky, the page is well formed and getting these url won't be too hard, if not...good luck.
Upvotes: 1
Reputation: 15931
You need an endpoint on the destination server that can respond with a list of files. Otherwise, you are just retrieving html.
Open the developer tools on this page, and paste the following code into the console:
jQuery
.get("http://stackoverflow.com/questions/16974040/how-to-grab-files-from-a-website-using-phonegap")
.success(function(html) {alert(html);});
I don't recommend the screen-scraping approach, but If you are ok with that, you will need to find a javascript html parser, and parse the results. If you have a service that can respond with an actual data-list, then, you would add each list item to the dom.
Upvotes: 0