title: How to escape special characters in query string sent via JQuery ajax function?
body: <p>I need to POST short messages to the server.  Sometimes they have special characters, like in this example:</p>
  
  <pre><code>&amp;message=Joining a game of Commands &amp; Colors: Ancients.
  </code></pre>
  
  <p>How do I escape special characters from a query string?</p>
  
  <p>I'm using Django.  Here's the field I need to encode:</p>
  
  <pre><code>&lt;textarea class="text-area" id="message" name="message" rows="3" cols="30"&gt;
     Joining a game of {{ game.name }}.
  &lt;/textarea&gt;
  </code></pre>
  
  <p>UPDATE:  I realize that the POST is going through JQuery's ajax function:</p>
  
  <pre><code>  $("#checkin-button").click(function() { 
            var mid = $("input#mid").val();
            var message = $("textarea#message").val();
            var facebook = $('input#facebook').is(':checked');
            var name = $("input#name").val();
            var bgg_id = $("input#bgg-id").val();
            var thumbnail = $("input#thumbnail").val();
            var dataString = 'mid='+mid+'&amp;message='+message+'&amp;facebook='+facebook+'&amp;name='+name+'&amp;bgg_id='+bgg_id+'&amp;thumbnail='+thumbnail;  
      $.ajax({  
        type: "POST",  
        url: "/game-checkin",  
        data: dataString,  
  </code></pre>
  
  <p>So I'm not passing that correctly (urlencoded) right?</p>
  
  <p>UPDATE: after realizing the issue was with JQuery, I was able to fix it by replacing the data variable assignment with:</p>
  
  <pre><code>    data: {"mid": mid, "message": message, "facebook": facebook, 
  "name": name, "bgg_id": bgg_id, "thumbnail": thumbnail}
  </code></pre>