title: Encoding hell! JSON ajax request (utf-8) to Latin1 uppercase characters
body: <p>I've ran into the following problem: the javascript lib i'm working on uses JSON cross-domain requests to get data from a Ruby on Rails backend:</p>
  
  <pre><code>function getData()
  {
      $.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")} })
  
      $.ajax({ 
                  url: backend_server + '?callback=parseData&amp;op=516',
          contentType: "application/json; charset=utf-8",
          dataType: 'jsonp',
          success: function (xml) {
             //console.log('success');
          }
      });
  }
  </code></pre>
  
  <p>The database from which RoR gets the data uses <strong>latin1</strong> internally but, if memory serves correct, this kind of JSON requests can only be done using UTF-8. </p>
  
  <p>The webpage's header reads:</p>
  
  <pre><code>Content-Type    text/html; charset=ISO-8859-1
  </code></pre>
  
  <p>And the page's metatag is also ISO-8859-1:</p>
  
  <pre><code>&lt;meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/&gt;
  </code></pre>
  
  <p>Now, after getting the data from the request, my Javascript library would parse it and, eventually, append it to a certain div inside the page (using the latest JQuery, not that it matters). All the latin characters were displayed incorrectly. </p>
  
  <p>I noticed that <strong>different browsers</strong> interpreted these characters differently (for some it worked fine, for others... not so much). I ended making a slight change to a utf8_decode function i found <a href="http://phpjs.org/functions/utf8_decode:576" rel="nofollow">here</a> (detecting the user agent and skipping the processing entirely for Safari, IE and Opera) but in the end I still can't display special Latin Uppercase characters with such as <em>"É", "Ç", "À", "Á", "Â" or "Ã".</em></p>
  
  <p>Any ideas? I am rather lost and could use some tips.
  Thanks in advance,
  J.</p>
  
  <p>PS: the top comment on the function's website is mine too.</p>
  
  <p>Edit1: I've also tried using <code>unescape(encodeURIComponent(str_data))</code> but it didn't work either</p>