title: HTML5 and the mystery charset
body: <p>This is my first post at SO so be gentle.  </p>
  
  <p>I am currently developing a web app that takes advantage of the new HTML5 target.result.  which allows me to read the content of a text file without having to upload anything to the server.</p>
  
  <p>The issue I am having is regarding the charset.  So, usually web content is generated via the page itself as a blog post, comment or whatever which is compliant with the charset of that page and the database configuration.  However, this new HTML5 functionality allows us to get text file content without knowing the original charset or format of the document in question.</p>
  
  <p>It makes sense to encode the data before it is posted by ajax so I have tried many different methods of converting the text to utf-8 and also via various dataTypes.  I have already gone through the whole chartset road, htaccess, meta, content-type.    </p>
  
  <p>It's no surprise that so many find the whole process of encoding, decoding URIs using different charsets, ASCII, different languages, and ajax dataTypes such a pain.</p>
  
  <p>I think the community could benefit from a solution that can obtain text from any type of text document regardless of charset or format, in any language and display it via an ajax request response in its original form with the added bonus of utf-8.  No weird symbols no one can read and finally bring an end to those diamond question marks.</p>
  
  <p>Here is an example of where I am now.  </p>
  
  <p>Copy this news article: <a href="http://www.nbcnews.com/news/world/airstrikes-kill-150-militants-tribal-lands-pakistan-n131436" rel="nofollow">News Article</a></p>
  
  <p>...and paste it here: <a href="http://www.percederberg.net/tools/text_converter.html" rel="nofollow">swiss converter tool</a></p>
  
  <p>No matter what configuration I use, I cannot get the apostrophes to display correctly in the bottom output, deja vu anyone?</p>
  
  <p>So how did google solve this problem with google translator?</p>
  
  <p><strong>EDIT:</strong> <em>It's also worth noting that the charsets of both ABC news and the swiss tool converter is utf-8. And you can clearly see that converting from utf-8 to utf-8 also gives the strange symbols even though they are exactly the same charset.</em>    </p>
  
  <p><strong>EDIST: 2</strong> Ok, so I managed to scramble a quick prototype and upload it to a remote server.  You can access it at <a href="http://www.babblingo.com" rel="nofollow">babblingo</a></p>
  
  <p>This is the javascript that posts the text via ajax:</p>
  
  <pre><code>function handleFileSelect(evt) {
  
  evt.stopPropagation();
  evt.preventDefault();
  
  var files = evt.dataTransfer.files;
  
  for (var i = 0, f; f = files[i]; i++) {
      var reader = new FileReader();
      reader.onload = (function(theFile) {
          return function(e) {
              var insertText = e.target.result;
              var fields = 'text=' + insertText;
              $.ajax({
                  type: "POST",
                  url: "ajax.php?action=addfile",
                  data: fields,
                  dataType: "json",
                  complete: function (data) {
                      if (data.responseJSON.message) {
                          $( "#modal-message h4" ).replaceWith( "&lt;h4 class='modal-title text-center'&gt;"+data.responseJSON.message+"&lt;/h4&gt;" );
                      }
                      if (data.responseJSON.report) {
                          $( "#report_box" ).replaceWith( '&lt;div id="report_box"&gt;'+data.responseJSON.report+'&lt;/div&gt;' );
                      }
                      if (data.responseJSON.import) {
                          $('#output_box').replaceWith('&lt;div id="output_box" class="hidden-print"&gt;'+data.responseJSON.import+'&lt;/div&gt;');
                      }
                      $('#modal-message').modal('show');
                      setTimeout(function() {$('#modal-message').modal('hide');}, 3000);
                  }
              });
  
  
          };
      })(f);
  
      reader.readAsText(f);
  }
  }
  </code></pre>