Jump to content

Search the Community

Showing results for tags 'read text file'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. Hallo all, I have a problem that I hope someone can help me with. I am using the Intel XDK with jQuery and Cordova. I do not unfortunately know which versions they are because I can't see it but the XDK has just update so I believe it is the newest versions whatever they are. I added a html file that I am working with at the moment to read a text file and eventually save to a database but for now to get it working I just want to place the contents in a div. I am using an input type="file" as below to select the file from the directory. <input class="wide-control" placeholder="Text File" type="file" name="txtFile" id="txtFile"> My code is in the index.html file (attached) and the input and div is in the other html file. My problem is lying where I get the file. I have put alerts before and after and I also have two versions of reading the file. the readText function is doing the jQuery.get or at the moment $.get and just absolutely nothing happens. The readFile function gives me an error: Uncaught TypeError: Cannot read property '0' of undefined index.html line 143. var Importer = { init: function() { var me = this $("#btnImport").bind("tap", function(e) { //me.readText() me.readFile() }); }, readText: function() { if (window.File && window.FileReader && window.FileList && window.Blob) { var myfile = $("#txtFile").val() var isAbs = $.mobile.path.isAbsoluteUrl(myfile); alert("Abs URL: " +isAbs); alert(myfile); $.get(myfile.file[0], function(data) { alert("$.get") //var myvar = data; //var myline = data.replace(/n/g,"<br />") //alert(myline); //$('#filecontents').html(data.replace(/n/g,'<br />')); }); } else { alert("Files are not supported"); }; }, // readtext readFile: function() { if (window.File && window.FileReader && window.FileList && window.Blob) { var fileSelected = $('#txtFile').val(); alert(fileSelected); var fileExtension = /text.*/; alert(fileExtension); var fileTobeRead = fileSelected.files[0]; if (fileTobeRead.type.match(fileExtension)) { var fileReader = new FileReader(); fileReader.onload = function (e) { var fileContents = $('#filecontents'); fileContents.innerText = fileReader.result; } fileReader.readAsText(fileTobeRead); } else { alert("Please select text file"); } } else { alert("Files are not supported"); }; } // readfile } //importer index.html
×
×
  • Create New...