Advertisement
Guest User

Descarga de archivos con phonegap

a guest
Apr 23rd, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. /*
  2. Explicacion:
  3.  
  4. dentro del javascript tenemos 2 funciones:
  5. - onDeviceReady que invoca al sistema de archivos. Se llama automaticamente cuando el dispositivo ha cargado. Esta es la que pega el pete
  6. - DescargaRepo2 que descarga un archivo. Se llama mediante un boton-link de jquery
  7. */
  8.  
  9.  
  10. //COMIENZA JAVASCRIPT/JQUERY
  11. <script type="text/javascript">
  12.  
  13. //con esta funcion obligamos al flujo de codigo a esperar hasta que el dispositivo haya terminado de cargar
  14. $(document).ready(function(){onDeviceReady();});
  15.  
  16.  
  17. /* funcion llamada cuando el dispositivo ha terminado de cargar */
  18. function onDeviceReady()
  19. {
  20. try {
  21. alert('start');
  22. //invocar al sistema de archivos. Aqui es donde falla
  23. window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
  24. } catch (e) {
  25. alert(e);
  26. }
  27. }
  28.  
  29.  
  30. function DescargaRepo2(id){
  31. alert(id);
  32. //-------------------------------
  33.  
  34. var fileDownloadEdit = new FileTransfer();
  35. alert("no descarga :(");
  36. var uri = encodeURI("http://dl.dropbox.com/u/97184921/editme.txt");
  37.  
  38. fileDownloadEdit.download(
  39. uri,
  40. './editme.txt',
  41. function(entry) {
  42. console.log("download complete: " + entry.fullPath);
  43. alert("File Downloaded. Click 'Read Editable Downloaded File' to see text");
  44. },
  45. function(error) {
  46. alert("download error source " + error.source);
  47. alert("download error target " + error.target);
  48. alert("upload error code" + error.code);
  49. }
  50. );
  51.  
  52.  
  53. //-------------------------------
  54. }
  55.  
  56.  
  57. </script>
  58.  
  59.  
  60.  
  61. <a href="#" onClick="DescargaRepo2('prueba');" data-role="button">Descargar desde Repositorio</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement