title: How to send parameters with same encoding from javascript?
body: <p>I have a javascript file that lots of people have embedded to their pages. Since I am hosting the file, I have control over that javascript file; I cannot control the way it is embedded because lots of people is using it already.</p>
  
  <p>This javascript file sends GET requests to my servlets, and the parameters passed with the request are recorded to DB. For example, javascript sends a request to <code>http://myserver.com/servlet?p1=123&amp;p2=aString</code> and then servlet records <code>123</code> and <code>aString</code> to DB somehow.</p>
  
  <p>Before sending strings I use <code>encodeURIComponent()</code> to encode it. But what I figured out is every client sends the same string with different encodings depending on either their browser or the site they are visiting. As a result, same strings are represented with different characters when it reaches servlet (so they are different strings).</p>
  
  <p>What I am trying to do is to convert the strings to one kind of encoding from javascript so when they reach the client same words are represented with same characters.</p>
  
  <p>How is this possible?</p>
  
  <p>PS. If there is a way to convert the encoding from Java it is also applicable.</p>
  
  <p><strong>Edit:</strong> To be more precise, I select some words from the page and send it to the server. That is where encoding causes problems.</p>
  
  <p><strong>Edit 2:</strong> I am NOT sending (and can't send) GET requests via <code>XMLHttpRequest</code>, because domains are different. I am using adding <code>script</code> tag to <code>head</code> method that @streetpc mentioned.</p>
  
  <p><strong>Edit 3:</strong> At the moment I am sanitizing the strings by replacing non-ASCII characters at javascript side, but I have a feeling that this is not the way to go:</p>
  
  <pre><code>function sanitize(word) {
      /*
      ğ : \u011f
      ü : \u00fc
      ş : \u015f
      ö : \u00f6
      ç : \u00e7
      ı : \u0131
      û : \u00fb
      */
      return encodeURIComponent(
              word.replace(/\u011f/g, '_g')
                  .replace(/\u00fc/g, '_u')
                  .replace(/\u00fb/g, '_u')
                  .replace(/\u015f/g, '_s')
                  .replace(/\u00f6/g, '_o')
                  .replace(/\u00e7/g, '_c')
                  .replace(/\u0131/g, '_i'));
  }
  </code></pre>